This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes private variable scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "private variable scope" Watch "private variable scope" New topic
Author

private variable scope

Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 254

The code attached below works fine and prints true which is fine but I could not understand why there was no compilation error on the equals function while it was trying to access the private member of another object. Could you please help me understanding this,


Regards
Salil Verma
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

The equals method is accessing private member on an instance of its own class. This is allowed. The members of the class have access to private members of objects of their own class...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
suman mitragupta
Greenhorn

Joined: Jul 23, 2009
Posts: 11
private varibale with object instance is ok.


Java Architect
scjp 1.5 sample questions scjp 1.6 sample questions
Atwal Usha
Ranch Hand

Joined: Sep 10, 2009
Posts: 137
Well, the private member is used within the class and it is allowed. There would have been compiler error if it would have been used outside the class.


Java Certification Exam Mock Tests: SCJA  SCJP 5  SCJP 6  SCJP 6 (Online Training)  SCJP 6 (Instructor Led Training)   SCWCD 5   SCBCD 5  SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private variable scope