| 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 ]
|
 |
 |
|
|
subject: inner class private method
|
|
|