为什么在application的main方法里一定要声明对象和创建对象同时做呢?(不好意思,我的分不多:( )
class test1
{
test2 test;
public static void main(String args[])
{
test = new test2();
}
}
class test2
{
}
------------------------------------------------------------------
这样的话就有以下错误了:
javac test1.java
test1.java:6: non-static variable test cannot be referenced from a static context
test = new test2();
------------------------------------------------------------------
class test1
{
public static void main(String args[])
{
test2 test = new test2();
}
}
class test2
{
}
-------------------------------------------------------------
这样就没有错误,这是为什么啊?