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

objects parameters

 
vkdandriyal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alexandre Bellezi Jos´┐Ż
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vkdandriyal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanxs Frank.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic