有一个类Tempa
public class Tempa {
public static int num = 0;
public synchronized void add(){
num++;
}
public static int getNum(){
return num;
}
public static void main(String[] args) throws InterruptedException {
// TODO 自动生成的方法存根
Tempa a = new Tempa();
for(int i = 0;i<100;i++){
Thread.sleep(500);
a.add();
}
}
}
里面有静态数值和一个静态方法
但是在另一个类里却取不到Temp
public class Temp {
public static void main(String[] args){
System.out.println(Tempa.getNum());
}
}
一直输出就是0,没有得到想要的数值,请大神帮忙看一下呢。谢谢啊