当前位置: 技术问答>java相关
关于Inner Class的简单问题?
来源: 互联网 发布时间:2015-05-25
本文导语: 我用Jcreator 一个关于Inner Class的例子,老是出问题,请大家帮忙找找原因: public class Outer2 { private int size; public class Inner { public void doStuff() { size++; } } public int getSize(){ ret...
我用Jcreator 一个关于Inner Class的例子,老是出问题,请大家帮忙找找原因:
public class Outer2 {
private int size;
public class Inner {
public void doStuff() {
size++;
}
}
public int getSize(){
return size;
}
}
public class TestInner {
public static void main(String[] args) {
Outer2 outer = new Outer2();
// Must create an Inner object relative to an Outer
Inner inner = outer.new Inner();
inner.doStuff();
System.out.println("Size is :"+outer.getSize());
}
}
Jcreator出错提示:
symbol : class Inner
location: class Outer.TestInner
Inner inner = outer.new Inner();
^
public class Outer2 {
private int size;
public class Inner {
public void doStuff() {
size++;
}
}
public int getSize(){
return size;
}
}
public class TestInner {
public static void main(String[] args) {
Outer2 outer = new Outer2();
// Must create an Inner object relative to an Outer
Inner inner = outer.new Inner();
inner.doStuff();
System.out.println("Size is :"+outer.getSize());
}
}
Jcreator出错提示:
symbol : class Inner
location: class Outer.TestInner
Inner inner = outer.new Inner();
^
|
Outer.Inner inner = outer.new Inner();
否则, 系统不认识内部类 Inner
否则, 系统不认识内部类 Inner
|
Outer.Inner inner = new Outer().new Inner();