wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enclosing class can access its inner class private members?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enclosing class can access its inner class private members??" Watch "enclosing class can access its inner class private members??" New topic
Author

enclosing class can access its inner class private members??

neel sri
Greenhorn

Joined: Feb 06, 2005
Posts: 13
One of the study material for SCJP says:

"Enclosing class members can access the private variables and methods of its member classes. These private fields and methods can be accessed by other member classes also."

I tried with the following code:

ofcourse it did not work as the inner1var is restricted to the class inner. Which means that statement is wrong. can anyone throw some light on this.

Thanks,
Neel
Preparing for SCJP 1.4

[ February 06, 2005: Message edited by: neel sri ]
[ February 06, 2005: Message edited by: Jim Yingst ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
it's exactly the other way around...


42
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Member classes can access private member variables of other member classes (in the same top-level class) the same way they can access public members of other member classes. That is, the word private does not prevent the access, but there can still be other things which prevent it. In this case, since inner1var and inner2var are nonstatic member variables, you need to have an instance of inner1 or inner2 to access them. This has nothing to do with public or private - it's true for any instance variable. You need an instance of the class that declares it. Try this:


"I'm not back." - Bill Harding, Twister
neel sri
Greenhorn

Joined: Feb 06, 2005
Posts: 13
Thanks for the ur replies ..
I was thinking the same ..
so can we conclude saying that the enclosing class cann't have direct access to the members of the inner classes?
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enclosing class can access its inner class private members??