public class Test{
        static int i=0;

        public int aMethod(){
         i++;
return i;
}
public static void main(String args[]){
Test test=new Test();
test.aMethod();
int j=test.aMethod();
System.out.println(j);
}
}

解决方案 »

  1.   

    public class Test{
     int i=0;
    public int aMethod(){

    i++;
    return i;
    }
    public static void main(String args[]){
    Test test=new Test();
    test.aMethod();
    int j=test.aMethod();
    System.out.println(j);
    }
    }
    要不改成这样...
      

  2.   

    import java.awt.*;
    import java.awt.event.*;public class Test{
     
    public int aMethod(){
    int i=0;
    i++;
    return i;
    }
    public static void main(String args[]){
    Test test=new Test();
    test.aMethod();
    int j=test.aMethod();
    System.out.println(j);
    }
    }
    刚才写错了...
      

  3.   

    主要就是不知道为什么static int i=0;
    这句回错误。如果按: baby429和 yybenq的方法程序就能正常运行了。
      

  4.   

    应该等于2
    你想问什莫阿
    aMethod()方法被调用2回
      

  5.   

    public class Test{
    public int aMethod(){
    int i=0;
    i++;
    return i;
    }
    public static void main(String args[]){
    Test test=new Test();
    //test.aMethod();
    int j=test.aMethod();
    System.out.println(j);
    }
    }打印结果等于1
      

  6.   

    问题:
    1.在java中,加static的一般是类方法或类变量,请认真看一下这个知识点
    2.为何两次用test.amethod()??
      

  7.   

    楼主真是搞笑,static变量怎么能写在方法中呢?static变量的意思是,在你还没有new这个类的时候它已经存在了,你这样写在方法中你说你让程序怎么办?-_-#