File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects themselves do not have" Watch "Objects themselves do not have" New topic

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.....

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46402
You can of course not gain access to the objects directly, only through references like,
private MyClass myObject;
protected YourClass yourObject;
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

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

Joined: Oct 02, 2003
Posts: 11955

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: 3381

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:
subject: Objects themselves do not have
It's not a secret anymore!