Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing private variables?

 
d jones
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I came across the following question in the Java Roundup rules quiz and I was very surprised with the answer.

Can one object access the private variable of another object of the same class?
Answer: Yes
Explanation: 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.

Could somebody please explain this to me? I don't understand!

Many Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic