Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:33:59+00:00 2026-05-17T23:33:59+00:00

As someone learning Java from scratch, who knows a little Python, I have been

  • 0

As someone learning Java from scratch, who knows a little Python, I have been wondering whats with all the access modifiers (public, static, protected…) in Java. I know what they mean, but why use them?

It’s just something that’s been bugging me, because whenever I write a new class and I write the instance variables I constantly have to ask myself do I want this variable to be private, public, final etc? I usually come to the conclusion I dont care for the majority of varibles and methods. There are a few instances where I know I will need to call the method from another class, but why not just make all methods public? Is it because in large projects you cant trust another developer isn’t going to start rummaging around and messing up your code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:34:00+00:00Added an answer on May 17, 2026 at 11:34 pm

    Use the minimal visibility modifier in each case. For example fields should be private in almost all cases.

    Methods can be:

    • private – if they are used only in the current class, as helpers.
    • protected, if you want them to be accessible to subclasses only, but not to other classes. This is when you design your class for inheritance, and you want to provide hooks for subclasses.
    • package-private – if you want to use these methods inside the same package, but don’t want to expose them to the outside world

    These all relate to API design – what functionality you want your API to expose and what not. That is – which methods are internal to your implementation, and which should be usable by classes that use your class to do their job.

    The advantage of all this is that you can change private/package-private methods without anyone else but your own class/package relying on them. Making them public ties you to supporting them. This is true not only when you are designing an API like the collections framework. It’s also true when you design your own API inside your own project. Classes have to be aware of much less methods (and hence are easier to change and support).

    See this presentation by Joshua Bloch on API design (specifically from 29:00)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Java and I have a quirk that I think only someone with
I just began learning Java. My friend who knows much more than me has
Over the past 2 years i've been learning languages like Java, C, C++, Python,
I was wondering is learning Python and Django a hard/time consuming process for someone
I am a noob in Java and am someone who is learning Java after
I have been a java web application developer,and now I work on .net framework.
I'm just starting out with learning Java, and have run into a problem. When
I am starting to learn Java a little after long time. And learning Netbeans
I come from a Java background and I am learning Objective C. I am
I'm learning about deadlocks in Java, and there's this sample code from Sun's official

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.