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

  • Home
  • SEARCH
  • 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 91999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:07:05+00:00 2026-05-10T23:07:05+00:00

So I was making a class the other day and used Eclipse’s method to

  • 0

So I was making a class the other day and used Eclipse’s method to create the equals method when I realized that it generated the following working code:

class Test {   private int privateInt;   [...]   public boolean equals(Object obj) {     [...]     Test t = (Test) obj;     if ( t.privateInt == privateInt ) {     [...]   } } 

t.privateInt..???? It’s suppose to be private! So I guess there is one more field visibility other than private, protected, package protected and public.

So what is happening here? How is this called? Where would somebody use this? Doesn’t this break encapsulation? What if the class didn’t have a mutator and I changed this? Does this happen to C++ as well? Is this an OO idiom? If not, then why did Java do it?

Generally, where can I find information about this?

Thank you.

  • 1 1 Answer
  • 3 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. 2026-05-10T23:07:05+00:00Added an answer on May 10, 2026 at 11:07 pm

    It’s accessible from different instances of the same class.

    According to this page (bolding mine):

    At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class.

    For clarity I’ll rewrite this line:

    if ( t.privateInt == this.privateInt ) 

    We can agree that ‘this.privateInt’ should be allowed: you are accessing it from within the instance of class Test that the message ‘equals’ has been sent to.

    It’s less clear that ‘t.privateInt’ should be visible, because t is a separate instance of class Test and we are not executing inside its equals method. However java allows this since both objects (t and this) are of the same class Test and can see each others private members.

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

Sidebar

Related Questions

I am making a utilities class that among other frequently used code have some
I am making a class Customer that has the following data members and properties:
I was playing around the other day with making a class to handle some
I tried making a wrapper class that encapsulates an object, a string (for naming
I am working on a project with MySQL,Hibernate,Java,GWT I am making an entity class
Im making a login/logout class that logs users in, sets cookies based on user's
wpdb class in wordpress is used for making connection to database. is there any
Im making a program for class that manages a Hotel. I have a function
I am working on a homework assignment for my into to programming class that
I often find I have class instances that are descendants of other class instances,

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.