• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object accessing private variable

 
tue march
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I have one doubt.

Can one object access other objects private variables.If so can
anybody explain.

i know that each object has its own private variables but how can other object access private variables of other object.

Remember both objects belong to same class.

Thanks,
Good guy
 
Nischal Tanna
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object can access other objects private variables (instance variables) simply by using <object>.<variable>, since private variables/methods of a class are accessible by instantiating the class. However private variables/methods are not accessible to child classes.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A private members can only be accessed inside the clas which it belongs to.
For Example private members of an Emp object can only be accessed in Emp class and not in any other class.

The code wont compile because "test has private access in memberTest.java"
[ April 26, 2005: Message edited by: Srinivasa Raghavan ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic