inner classes - How can I access a method that is inside a class that is inside another method of another class in Java -
below program compiles how access m2() method of class b inside m1() method of class a.
class a{ public void m1() { system.out.println("a-m1"); class b{ public void m2() { system.out.println("b-m2"); } }//end of class b }//end of m1() method }// end of class
it depends on scope. if want invoke m2() @ end of m1(), it's simple creating new instance of b , calling method.
new b().m2() if want call outside method or before declaration, won't allow because of scope.
if case, should consider promoting scope class-level.
Comments
Post a Comment