aspose file tools
The moose likes Beginning Java and the fly likes Rules round up question doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rules round up question doubt" Watch "Rules round up question doubt" New topic
Author

Rules round up question doubt

Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
Can one object access the private variable of another object of the same class?

Private means private to the class not object. So 2 objects of teh same class can access each other private data.

My doubt is.. how can an obj access another objects data first place?
What does this statement mean?? If teh answer is right can anyoen give an example code for this??
Sorry if its a primitive question.
Thank you sirisha


If you worry you cannot work... If you work you need not worry
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

When you call the method "m" of class "C", you have to supply another instance of "C" as the argument. "m" takes the value of "i" from the other instance of "C", and sets its own variable "i" to that value plus one.



[Jess in Action][AskingGoodQuestions]
Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
Thank you
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Rules round up question doubt