这是代码
public class Stack
{
private class Node{
...
}
...
public static void main(String[] args){
Node node = new Node(); // generates a compiling error
}
}
Run Code Online (Sandbox Code Playgroud)
错误说:
无法从静态上下文引用非静态类Node
为什么我不应该在main()方法中引用Node类?
这是代码.
public class Test {
class InnerClass{
}
public static void main(String[] args){
InnerClass ic = new InnerClass();
}
}
Run Code Online (Sandbox Code Playgroud)
它说错误信息
non-static variable this cannot be referenced from a static context
after creation of object ic.
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我理由吗?
谢谢