在java中,静态方法只能访问静态变量,那么由于main()是静态的,而class也包含静态和非静态变量,那么为什么main()是静态的,可以访问类的非静态成员呢?
发布于 2016-07-14 01:19:48
添加实例:
public static void main(String args[]){
ThisClass tc = new ThisClass();
tc.nonStaticVar//do whatever
}这不会重新触发main,因为它没有被调用。
https://stackoverflow.com/questions/38357973
复制相似问题