Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects themselves do not have

 
Phillipe Rodrigues
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects themselves do not have any accessibility modifiers, only the object references do.

please explain the above.....
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can of course not gain access to the objects directly, only through references like,
private MyClass myObject;
protected YourClass yourObject;
etc.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well objects are like persons in your class and access modifiers are like some specialties to the properties of objects. Say, take a name having # of vowels etc but person being an object itself, it may not possess these.

Of course, how do you get access to a person? Through his roll number in a class --- nothing but a reference (more like a pointer) that knows how to reach an object!

Now when it comes to 'access modifiers' -- a means to control the access, references are also members of a class in which it is declared. so they are very well eligible to hold those.

The example what Campbell gave explains you very clearly.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert Bates and Kathy Sierra have come up with what I think is a pretty good analogy. Think of the object as a TV, and a reference as a remote control. you never touch the TV itself, only the remote. you use that to access the functions of the TV.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course! Thank you fred!

That's one of the beautiful and undeniable examples!
[ April 10, 2008: Message edited by: Raghavan Muthu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic