main()里少了些东西~:)public static void main( String args[] ){                f1();
                f2();
                System.out.println("End!");
        }

解决方案 »

  1.   

    你的f1()是一个静态的方法
    这个方法在编译的时候就会执行
    而你这样this.f2();是一种动态的调用,在静态的方法里面是不可以有动态的调用的
      

  2.   

    对啊,在静态的方法里面是不可以有动态的调用的,因为调用静态方法的时候不能保证对象实例已经存在。这个书上应该说到了吧。
     同样,f1()是static,而this涉及到具体实例,所以不能引用this.
      

  3.   

    public class ThisClass9 {
            public void f1() {//如果没有关键字 static ,编译出错:
                              //non-static method f1() cannot be
                              //referenced from a static context
                              
                              //f2()一样。
                    f2();
                    this.f2();//如果不注释掉这句,编译通不过:
                                //non-static variable this cannot 
                                //be referenced from a static context
            }
            public  void f2() {
                    System.out.println("2nd functiong");
            }
            public static void main( String args[] ){
                   f1();
                   f2();
                   System.out.println("End!");
            }
    }
    这样?编译通不过啊!~你按题目写一个给我看看吧!谢谢了~
      

  4.   

    public class ThisClass9 {
            public static void f1() {
                    f2();
                    f2();
    }
            public  static void f2() {
                    System.out.println("2nd functiong");
            }
            public static void main( String args[] ){
                   f1();
                   f2();
                   System.out.println("End!");
            }
    }
      

  5.   

    public class ThisClass9 {
            public void f1() {//如果没有关键字 static ,编译出错:
                              //non-static method f1() cannot be
                              //referenced from a static context
                              
                              //f2()一样。
                    f2();
                    this.f2();//如果不注释掉这句,编译通不过:
                                //non-static variable this cannot 
                                //be referenced from a static context
            }
            public  void f2() {
                    System.out.println("2nd functiong");
            }
            
            public static void main( String args[] ){
                   ThisClass9 t = new ThisClass9();            //我加的
                   t.f1();
                   t.f2();
                   System.out.println("End!");
            }
    }ok?呵呵
                    '''             
                   (0 0)            
       +-----oOO----(_)------------+
       |                           |
       |         有感而发!         |
       |                           |
       |                           |
       +------------------oOO------+
                  |__|__|           
                   || ||            
                  ooO Ooo
      

  6.   

    .....................................
    新学Java的,不会因为这而气死。虫子有创意,but i'm very sorry:
    non-static variable this cannot be referenced from a static context
                         this.f2();//如果不注释掉这句,编译通不过:
                         ^
      

  7.   

    好人没看题目。   必须有this调用啊!~~
      

  8.   

    其实就一句话,static的发方法内部不能调用非static的方法(除非从参数里传了那个非static方法的实例的句柄进来)
      

  9.   

    public static class ThisClass9 {
            public static void f1() {//如果没有关键字 static ,编译出错:
                              //non-static method f1() cannot be
                              //referenced from a static context
                              
                              //f2()一样。
                    f2();
                    this.f2();//如果不注释掉这句,编译通不过:
                                //non-static variable this cannot 
                                //be referenced from a static context
            }
            public static void f2() {
                    System.out.println("2nd functiong");
            }
            public static void main( String args[] ){
                    System.out.println("End!");
            }
    }
      

  10.   

    楼主你在说什么?
    不是你写的函数有问题,是你调用的问题。请赐教                '''             
                   (0 0)            
       +-----oOO----(_)------------+
       |                           |
       |         有感而发!         |
       |                           |
       |                           |
       +------------------oOO------+
                  |__|__|           
                   || ||            
                  ooO Ooo
      

  11.   

    //*撰写具有两个函数的class,在第一个函数内调用第二个函数两次:第一次调用时不
     //*使用this,第二次调用时使用this。你们别看我写的那个了,根据上面的条件给我个class. OK?
      

  12.   

    public class TestClass{
            public static int i = 1;
            
            public void f1() {
             System.out.println("used the 1st function!");
                f2();
                this.f2();
            }
            public  void f2() {
                System.out.println("used the 2nd function! " + i + "time.");
                i++;
            }
            
            public static void main( String args[] ){
                TestClass t = new TestClass();            
                t.f1();
                t.f2();
                System.out.println("ok? my friend?! he he...");
            }
    }
                    '''             
                   (0 0)            
       +-----oOO----(_)------------+
       |                           |
       |         有感而发!         |
       |                           |
       |                           |
       +------------------oOO------+
                  |__|__|           
                   || ||            
                  ooO Ooo