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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:49:13+00:00 2026-05-30T13:49:13+00:00

In java, do we really have to do that in order our variable or

  • 0

In java, do we really have to do that in order our variable or method to be public? For example:

void aaa() {
...
}

or

public void aaa() {
...
}

If it is a must, why?

  • 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-30T13:49:14+00:00Added an answer on May 30, 2026 at 1:49 pm

    Well that’s not a variable, that’s a method – but yes, you have to do that to make a method public. If you don’t, it has the default package access, and won’t be accessible from other packages. You should judge for yourself whether any particular method you write should be accessible only within the same class (make it private) to subclasses (make it protected), to the package (leave the default; you can’t state package access explicitly, unfortunately) or to everything (make it public).

    (This is a slight simplification of the access modifiers, but it’s a start.)

    As for why this is the case – typically you should limit visibility so that your type only exposes the methods which really make sense for the concept it’s trying to encapsulate. You may have many more private methods which are implementation-specific, and which the outside world shouldn’t know or care about.

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

Sidebar

Related Questions

I have a really simple Java class that effectively decorates a Map with input
Every method you create in Java you have to call, for example, say you
I'm used to doing Java programming, where you never really have to think about
i have a really basic java program just one .java/.class file (.java uncompiled .class
I have a really strange enum bug in Java. for(Answer ans : assessmentResult.getAnswersAsList()) {
I have a really strange issue. I am working on a Java SWING application
I've got one really big .java class file that has a lot of members.
I am really new to Java and I read that synchronized is very expensive
I have developed a Java aplication that is currently being run by double-clicking on
I have an open source Java application that uses Hibernate and HSQLDB for persistence.

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.