Killvin's blog

卧居古城,静候伯乐

原创 Java Nested class收藏

URL : http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html

网上的一些关于内部类的概念是不完整的,还是看看SUN的文档上的标准答案。
...

Like other members, a nested class can be declared static (or not). A static nested class is called just that: a static nested class. A nonstatic nested class is called an inner class.

- Nested class分为静态Static nested class 的和非静态的 inner class, 在SUN的眼里只有Nested Class!!


As with static methods and variables, which we call class methods and variables, a static nested class is associated with its enclosing class. And like class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class — it can use them only through an object reference.

- 静态的Static nested class是不可以直接调用它的外部类enclosing class的,但是可以通过外部类的引用来调用,就像你在一个类中写了main方法一样。
...

As with instance methods and variables, an inner class is associated with an instance of its enclosing class and has direct access to that object's instance variables and methods. Also, because an inner class is associated with an instance, it cannot define any static members itself.

-非静态类inner class 可以自由的引用外部类的属性和方法,但是它与一个实例绑定在了以其,不可以定义静态的属性、方法(这点不是很理解,可能需要看JVM的类实现)

...
class EnclosingClass {
...
class InnerClass {
...
}
}


The interesting feature about the relationship between these two classes is not that InnerClass is syntactically defined within EnclosingClass. Rather, it's that an instance of InnerClass can exist only within an instance of EnclosingClass and that it has direct access to the instance variables and methods of its enclosing instance. The next figure illustrates this idea.


-图形化的嵌入类与外部类的关系

发表于 @ 2006年01月10日 09:44:00|评论(loading...)

新一篇: 初识Java内部类 | 旧一篇: Java基础问题:java.lang.String - intern()

用户操作
[即时聊天] [发私信] [加为好友]
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
的公告
  • 本Blog规则
    这里将成为纯粹记录本人学习经历的地方,任何与技术无关的评论(无论是褒义还是贬义)都将被删除!当然,本人将不再对某人或者某事发表任何意见(技术观点除外),同时对于以前的一些言论如果伤害到某个人,请谅解。
  • 文章分类
    收藏
      Friend's BLOG
      沉没的海洋
      蝈蝈俊.net
      韩磊@CSDN
      存档
      软件项目交易
      Csdn Blog version 3.1a
      Copyright ©