| Author |
doubt from ranch roundup
|
amit taneja
Ranch Hand
Joined: Mar 14, 2003
Posts: 806
|
|
hi in question from roundup Q can one object access a pvt variable of another object of the same class ? A. yes, pvt means "pvt to the class" not "pvt to the object". so two objects of the same class could access each other's pvt data. i didn't understand the question well ? pls give one eg. thanx
|
Thanks and Regards,<br />Amit Taneja
|
 |
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
If two objects are from the 'same class' then those objects can access each others private members. When you think private, think class level, not object level. Hope this helps. Cheers, Marzo.
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
|
 |
Philip Heller
author
Ranch Hand
Joined: Oct 24, 2000
Posts: 119
|
|
Here's an example: See how the method accesses not only the age of the current Fish instance, but also the age of another instance? Perfectly legal.
|
Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
|
 |
Timmy Marks
Ranch Hand
Joined: Dec 01, 2003
Posts: 226
|
|
|
However, you didn't make age private in Fish. Does it still work if age is private?
|
 |
vjy chin
Ranch Hand
Joined: Feb 17, 2005
Posts: 279
|
|
Yes, it still works if age is private in Fish. Look at the example
|
 |
 |
|
|
subject: doubt from ranch roundup
|
|
|