File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rules Roundup Question

 
Jayant Raj
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Richard Green
Ranch Hand
Posts: 536
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic