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);
}
}
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);
}
}
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);
}
}
要不改成这样...
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);
}
}
刚才写错了...
这句回错误。如果按: baby429和 yybenq的方法程序就能正常运行了。
你想问什莫阿
aMethod()方法被调用2回
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
1.在java中,加static的一般是类方法或类变量,请认真看一下这个知识点
2.为何两次用test.amethod()??