jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes object accessing private variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object accessing private variable" Watch "object accessing private variable" New topic

object accessing private variable

tue march

Joined: Mar 09, 2005
Posts: 16
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.

Good guy
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
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

Joined: Sep 28, 2004
Posts: 1228
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 ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
I agree. Here's the link: http://aspose.com/file-tools
subject: object accessing private variable
jQuery in Action, 3rd edition