class a
{
int x=90;
public void test()
{
final int x=99;
class b
  {
  public void getb()
  {
  System.out.println(x);
  }
  }
}
public static void main(String[] args)
{
a a2=new a();
a2.test();
}
}该怎么在main方法中调用getb()方法呢?

解决方案 »

  1.   

    只能:
    直接在class a 
    的内部类class b里调用test()方法了。
      

  2.   

    class c{
     public void getb(){
     
     }
    }
    class a
    {
    int x=90;
    public c test()
    {
    final int x=99;
    class b extends c
      {
      public void getb()
      {
      System.out.println(x);
      }
      }
     final b bb= new b();
     return bb;
    }
    public static void main(String[] args)
    {
    a a2=new a();
    c cc=a2.test();
    a2.test().getb();
    }
      

  3.   

    你可以试下在方法里面创建一个b 的对象,然后再调用getb()方法。
      

  4.   

    class c
    {
         public void getb()
         {
             
         }
    }
    class a
    {
         int x=90;
         public c test()
         {
            final int x=99;
            class b extends c
            {
              public void getb()
              {
                System.out.println(x);
              }
            }
            c cc=new b();
            return cc;
         }
         public static void main(String[] args)
         {
            a a2=new a();
            a2.test().getb();
         }
    } 这是我改的.不明白的是c cc=a2.test();这句的作用是什么,不写也没事啊!