日期:2014-05-20  浏览次数:20620 次

这为什么都不行
1
class   a  
{  
a   A=new   a();  
a()   {  
}  
void   c()   {  
}  
}
  class   b  
{
a   B;  
void   f()  
{   B.c();  
              }  
public   static   void   main(String[]   args)
                           
{   b   test   =   new   b();//这是初始创建的对象
b   n;                               //
n.f();                           //这样为什么不行
      }
    }
2
class   a  
{  
a   A=new   a();  
a()   {  
}  
void   c()   {  
}  
}
  class   b  
{
  void   f()  
{   a   B;     //这样也不行
  B.c();  
              }  
public   static   void   main(String[]   args)
                           
{   b     =   new   b();
  test.f();                          
      }
    }
3
class   a  
{  
a()   {  
      }  
void   c()   {  
        }  
}
  class   b  
{
  void   f()  
{   a   A=new   a();
    a   B;     //这样还不行
  B.c();  
              }  
public   static   void   main(String[]   args)
                           
{   b     =   new   b();
  test.f();                          
      }
    }
反正以上都是报错
只有把a   的引用放到所有的方法之外   非静态的方法才能用对象的引用去调用方法
在静态的方法中还不能建立个引用去调用方法   只能是用   创建的对象去调用这又是为什么?为什么非静态的就能用引用去调用方法呢?而且引用一定要在个方法之外呢?

------解决方案--------------------
好多 眼睛花了 UP
------解决方案--------------------
你刷屏么?