Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

objects parameters

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanxs Frank.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic