This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class private method

 
preeti khane
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic