下面的语句我在编译的时候出现这样的提示:无法从静态上下文中引用非静态方法;我不知道怎么改,请各位指教
class D
{
      void fn1()
      {
      }
}abstract class E
{
       abstract void fn2();
       
}class F extends D
{
       E getE()
       {
            return new E()
            {
                public void fn2()
                {
                }
            };
       }
}class Text
{
     public void method1(D d)
     {
             d.fn1();
     }
     public void method2(E e)
     {
             e.fn2();
     }
     public static void main (String [] args)
     {
            F f=new F();
            method1(f);
            method2(f.getE());
     }
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【wzclj001】截止到2008-07-14 09:14:02的历史汇总数据(不包括此帖):
    发帖的总数量:5                        发帖的总分数:90                       每贴平均分数:18                       
    回帖的总数量:5                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:4                        结贴的总分数:70                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:80.00 %               结分的百分比:77.78 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

      public static void main (String [] args) 
        { 
              F f=new F(); 
              method1(f); 
              method2(f.getE()); 
        } 这里啊,老兄,你要这样
      public static void main (String [] args) 
        { 
              F f=new F(); 
              Text  t=new Text();
              t.method1(f); 
              t.method2(f.getE()); 
        } 不能在静态方法中直接调用非静态的成员或方法。!!
      

  3.   

    method1和method1是Text类的非静态方法,由对象来调用.
      

  4.   

    public static void main (String [] args)
        {
              F f=new F();
              Text  t=new Text();
              t.method1(f);
              t.method2(f.getE());
        } 
    要先创建对象,才能通过对象调用对象的方法!