内部类如何调用主类的同名函数?class A{
    public void getA(){}
    
    class B{
        public void getA(){
            //这里如何调用主类的getA()?
        }
    }
}

解决方案 »

  1.   

    /**
     * Created by IntelliJ IDEA.
     * User: gaoyong
     * Date: 2011-10-11
     * Time: 18:23:13
     * To change this template use File | Settings | File Templates.
     */
    public class A{
        public void getA(){
            System.out.println("主类getA()方法");
        }    class B{
            public void getA(){
                System.out.println("内部类调用getA()方法");
                A.this.getA();
            }
        }    public static void main(String[] args) {
            A a=new A();
            a.new B().getA();
        }
    }