This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can one object access the private variable of another object of the same class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can one object access the private variable of another object of the same class?" Watch "Can one object access the private variable of another object of the same class?" New topic
Author

Can one object access the private variable of another object of the same class?

Mike Ngo
Ranch Hand

Joined: Oct 16, 2006
Posts: 89
I came across this question in the javaranch mock question.

#208 Can one object access the private variable of another object of the same class?
Answer: Yes. Private means �private to the class�. Not private to the object.
So two objects of the same class could access each other�s private data.

Can someone explain or give an example? I don't see how it can be done.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Mike Ngo
Ranch Hand

Joined: Oct 16, 2006
Posts: 89
Thanks.
 
Don't get me started about those stupid light bulbs.
 
subject: Can one object access the private variable of another object of the same class?
 
Similar Threads
Rules Roundup Question
Java Rule Round Up: Question 80
Private Variables
JavaRanch Rule Round-up Game?
Accessing private variable