Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class private method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class private method" Watch "inner class private method" New topic
Author

inner class private method

preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93

Shouldn't the compiler complain on accessing the private method of the inner class at line 3? I know it doesn't but curious as to why? Usually private methods are not accessible outside the class definition....what makes this inner class different?
G Nadeem
Ranch Hand

Joined: Apr 25, 2003
Posts: 48
Hi,
that is right. however enclosing classes can access private members of the nested classes. as nested classes/inner classes are there to serve the enclosing object (Kathy), so it make sense.
so as the code is being accessed within Test009, its valid. if u try to access this method out side Test009, u will get exactly what u said. i.e compile time error stating the method is private.
class Test{
public static void main(String [] s){
Test009.Inner inner1=new Test009().new Inner();
inner1.method();//Oooops...
}
}
[ June 06, 2003: Message edited by: G Nadeem ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class private method
 
Similar Threads
scope
Inner classes
Sun Guoqiao's Mock Exam 2 Quest. 9
Circularity
Inner Classes