permaculture playing cards*
The moose likes Beginning Java and the fly likes Objects themselves do not have Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects themselves do not have" Watch "Objects themselves do not have" New topic
Author

Objects themselves do not have

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
Objects themselves do not have any accessibility modifiers, only the object references do.

please explain the above.....


Thanks,
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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

Joined: Apr 20, 2006
Posts: 3344

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.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10911
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Yes, of course! Thank you fred!

That's one of the beautiful and undeniable examples!
[ April 10, 2008: Message edited by: Raghavan Muthu ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects themselves do not have
 
Similar Threads
If wrapper classes are imutable why is the value of Integer i changing?
Object visibility
Usefulness of learning swings
array doubt
what is the example for polymorphism?