/** CastTest.java */
public class CastTest
{
class A{}
public static void main(String args[])
{
A a = new A();
}
}
輸出結果:
CastTest.java:7: error: non-static variable this cannot be referenced from a
static context
A a = new A();
^
1 error
static context
A a = new A();
^
1 error
我不懂,哪裡錯了?
若是把 class A 寫在外面,就過了
/** CastTest2.java
*/
class A{}
public class CastTest
{
public static void main(String args[])
{
A a = new A();
}
}
沒有留言:
張貼留言