全局变量在main方法中出现不能将一个非静态变量赋值给静态变量
public class HelloWorld { static int var=1;//去掉static就不对了,为什么 void call() { int cal; System.out.println("var:"+var);} void sendMessage() {int cal; System.out.println("var"+var);} public static void main(String[] args) { //int var=5; HelloWorld phone=new HelloWorld(); phone.call(); System.out.println(var);//为什么var一定要是static类型,如果不是static就会报错 } }