aspose file tools*
The moose likes Beginning Java and the fly likes objects parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "objects parameters" Watch "objects parameters" New topic
Author

objects parameters

vkdandriyal
Greenhorn

Joined: Jun 02, 2000
Posts: 4
While doing mock exam on this site. I got a question regarding
objects(I forgot its sr no).
Question : Can one object access a private variable of another object of the same class?
Its answer was : Yes, Private means : "Private to the class",
not "Private to the object". So two objects of same class could access each others's private data.
Its confused me. Prior to this Q/A my firm belief was that
two objects of same class can not share private members any way.
Can anyone help me to sortout this confusion, if possible, supply the real example too.
------------------
Vijay K D


Vijay K D
Alexandre Bellezi Jos�
Greenhorn

Joined: Aug 03, 2007
Posts: 16
variables are either accessible to class members or they are not.
no matter how many objects of a class you make the private variables of a class are accessible to each and every object that has been instantiated for that class.
variables access is class specific and not object specific.
i think you must clear your fundas of classes and objects
and i shall be happy if i could help you in any way.
be happy


[This message has been edited by abj (edited June 02, 2000).]
vkdandriyal
Greenhorn

Joined: Jun 02, 2000
Posts: 4
thanxs for your frank comments.
Actually i am confused with the follwong line.
So two objects of same class could access each others's private data.
Can you provide a real life example
or provide a simple example with code
[This message has been edited by vkdandriyal (edited June 02, 2000).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
A common example might be as follows:

In the above case, it is vital that one object of the class can access the private variables of another object of the same class. This kind of "copy constructor" occurs quite often in real systems.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
vkdandriyal
Greenhorn

Joined: Jun 02, 2000
Posts: 4
Thanxs Frank.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: objects parameters