• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Mike Ngo
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Mike Ngo
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!