thinking in java中 inner calass的一个问题?

toto2004 2005-03-28 06:41:00
这个问题是我在看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; }
}
中不就有数据成员和函数吗?有谁能否解释一下吗?
...全文
157 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
killme2008 2005-03-30
  • 打赏
  • 举报
回复
理解错误
toto2004 2005-03-29
  • 打赏
  • 举报
回复
up
飞行的兔子 2005-03-28
  • 打赏
  • 举报
回复
楼主你理解错了,not-static内隐类是不可以有static成员,而不是不可以有数据成员和函数,static内隐类可以拥有static成员和函数!
你把整句话再仔细读一遍!

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧