java inner class

@see http://www.cnblogs.com/aigongsi/archive/2012/04/24/2467183.html

@http://webservices.ctocio.com.cn/wsdev/428/9058928.shtml

@see http://duqiangcise.iteye.com/blog/697476


JLS(java语言规范)

A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class. 

An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (§8.7) or member inter- faces.


If you don't need a connection between the inner-class object and the out-class object,then you can make the inner calss static. This is  commonly called a nested class.To understand the meaning of static when applied to inner classes,you must remember that the object of an ordinary inner class implictly keeps a reference to the object of the enclosing class that created it.This is not true,however,when you say an inner class is static.A nested class means:

1. You don't need an outer-class object in order to create an object of a nested class.

2. You can't access a non-static outer-class object from an object of a nested class.

Nested classes are different from ordinary inner classes in another way,as well.Fields and methods in ordinary inner classes can only be at the outer level of a class,so ordinary inner classes cannot have static data,static fields,or nested classes.However,nested classes can have all of these.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值