62,614
社区成员
发帖
与我相关
我的任务
分享
public class T {
static int $i;
}
public static void myfun() {
this.i;
}
public class Test3 {
public static int $i=5;
public int k;
public Test3(int k) {
this.k=k;
Test3.$i=k;
}
public static void main(String[] args) {
Test3 test1 = new Test3(10);
Test3 test2 = new Test3(5);
System.out.println(test1.k+" "+test1.$i);
System.out.println(test2.k+" "+test2.$i);
}
}
结果:
10 5
5 5
这就是static和非static的区别
public class T {
static int $i;
}
public static void myfun() {
T.i;
}
public class T {
static int i;
public static void myfun() {
this.i = 9;
}
}