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 9212767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:36:02+00:00 2026-06-18T01:36:02+00:00

So 2 questions: Should I use for my classes public or package access? In

  • 0

So 2 questions:

  1. Should I use for my classes public or package access? In every project all my classes are kept in one package and I never use any methods from them in other projects. So do I need public access? I think package would be ok for me. And would be safer.
  2. I know habit of making fields private and making getters and setters for them. I also understand idea of hermetic, however everywhere I read about philosophy of making getters and setters I get only one reason: “You must do getters or setters so you are sure that one variable is not directly used in other part of program. Thanks to this you can be sure that you can make in such getter changes (like if statement which decides what value return) and be sure that every part will behave like that”. But in 99.9% getters just return class private value. Almost every time getter have just 1 line “return XXX”. So are there any other possiblites of using getters? And setters? I once deleted getters and setters from my project, made fields public and what I got was that my project got almost 30% smaller.
  • 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-06-18T01:36:03+00:00Added an answer on June 18, 2026 at 1:36 am

    It’s generally a good idea to make all fields private, and to implement getters and setters as needed. That way, you can make sure that the fields aren’t used/changed in a way that is unintended. For example, you can add error checking code to your setters, to make sure fields aren’t set to values that will break other things. If other classes can set the field directly, you can’t prevent that.

    If you have a good reason to make a field with package visibility, or public, then of course you can do so, but you have to be aware of what problems that can cause if other people/classes use your fields the wrong way.

    It probably doesn’t make a lot of difference in your small project, because you know not to set fields to the wrong values, or screw up otherwise – but if other people use your classes or your project grows in size, you will appreciate the fact that the actual fields are private and you can control access via the getters/setters.

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

Sidebar

Related Questions

Other questions dealing with use of match_parent pre 2.2 have answers stating one should
I have two questions. 1) Should you always use a using statement on a
The question pretty much says it all. What supported JVM GC should we use
This is the common structure of all of my classes: public class User {
I don't know which title I should use for this question. I have a
Recently I have asked a question about what I should use to create self-contained
My Question is a design question. Should I use a StringBuilder and read the
My question is really simple. When should I use List, IEnumerable and ArrayList. Here's
This should be a elementary question but why is better to use something like
My question is what is better to use in generating columns in SQL. Should

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.