This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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"
[ 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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: object accessing private variable
It's not a secret anymore!