aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Rules Roundup Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Rules Roundup Question" Watch "Rules Roundup Question" New topic
Author

Rules Roundup Question

Jayant Raj
Ranch Hand

Joined: Mar 11, 2004
Posts: 42
Hi,

I came across this question in the Rules Roundup game.

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

Answer : Yes

Please explain.. preferably with an example.


regards,<br />Jayant Raj<br /> <br />SCJP 1.4 [98%]<br />SCWCD 1.4 [91%]<br />SCBCD [In Progress]
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Access modifiers (private, default, protected, public) ... technically "default" isn't an access modifier since you don't type it out--but still!

Anyways, those just deal with visibility by the class, not an object. Check this out:



Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
"Private" means Private to the class, not to the object

ie.,
class A{
private String xxx = "Blah!";

void testSomething(A obj){
obj.xxx = "valid"; // this is valid
}
}


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rules Roundup Question