thinking in java中 inner calass的一个问题?
这个问题是我在看thinking in java 中看到的原话如下:
...non-static inner class 内的所有数据和函数都只能够位于class的外层,所以它不能够拥有任何static data、static fields、static inner class。然而static inner classes可以拥有那些东西
但是我在书中随便找了个代码 如下
//: c08:Parcel1.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Creating inner classes.
public class Parcel1 {
class Contents {
private int i = 11;
public int value() { return i; }
}
class Destination {
private String label;
Destination(String whereTo) {
label = whereTo;
}
String readLabel() { return label; }
}
// Using inner classes looks just like
// using any other class, within Parcel1:
public void ship(String dest) {
Contents c = new Contents();
Destination d = new Destination(dest);
System.out.println(d.readLabel());
}
public static void main(String[] args) {
Parcel1 p = new Parcel1();
p.ship("Tanzania");
}
} ///:~
如代码所示非静态内隐类
class Contents {
private int i = 11;
public int value() { return i; }
}
中不就有数据成员和函数吗?有谁能否解释一下吗?