当前位置: 技术问答>java相关
内部类中一个static变量问题?
来源: 互联网 发布时间:2015-11-18
本文导语: public class EnclosingClass { private static int staticvar=100; public int instancevar=500; public static void main(String[] args) { EnclosingClass outer=new EnclosingClass(); EnclosingClass.InnerClass inner=outer.new InnerClass(); } p...
public class EnclosingClass
{
private static int staticvar=100;
public int instancevar=500;
public static void main(String[] args)
{
EnclosingClass outer=new EnclosingClass();
EnclosingClass.InnerClass inner=outer.new InnerClass();
}
public static class InnerClass
{
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
}
}
运行出错:
EnclosingClass.java:13: expected
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
^
EnclosingClass.java:13: cannot resolve symbol
symbol : class out
location: class java.lang.System
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
^
EnclosingClass.java:9: qualified new of static class
EnclosingClass.InnerClass inner=outer.new InnerClass();
^
3 errors
请指点一下?
{
private static int staticvar=100;
public int instancevar=500;
public static void main(String[] args)
{
EnclosingClass outer=new EnclosingClass();
EnclosingClass.InnerClass inner=outer.new InnerClass();
}
public static class InnerClass
{
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
}
}
运行出错:
EnclosingClass.java:13: expected
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
^
EnclosingClass.java:13: cannot resolve symbol
symbol : class out
location: class java.lang.System
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
^
EnclosingClass.java:9: qualified new of static class
EnclosingClass.InnerClass inner=outer.new InnerClass();
^
3 errors
请指点一下?
|
我靠,你这个程序怎么写的,思路乱的一B
public static class InnerClass
{
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
}
这是个类吗?
有这么写的吗
EnclosingClass.this.staticvar);
this还有这么用的,我算见识了
outer.new InnerClass();
这句话又是什么意思,谁叫你这么写的?
public static class InnerClass
{
System.out.println("statcivar:"+EnclosingClass.this.staticvar);
}
这是个类吗?
有这么写的吗
EnclosingClass.this.staticvar);
this还有这么用的,我算见识了
outer.new InnerClass();
这句话又是什么意思,谁叫你这么写的?