本站首页    管理页面    写新日志    退出


[Java]Java Tutorial 读书笔记(Trail Two:Learning the Java Language_4_Classes and Inheritance_2_Managing Inheritance_3_Implementing Nested Classes)
liyang 发表于 2005/6/30 9:42:50

Managing Inheritance Understanding Inheritance 子类对于父类的成员来说,可以继承(use)、隐藏(hide)、覆盖(override)。隐藏是对变量来说的;覆盖是对方法来说的。二者在表象上的共同之处在于子类在其内部定义了一个和父类相同名字的成员;对于被隐藏的变量和被覆盖的方法而言都可以通过super来访问。 对于方法的覆盖,要多说两句: 1、The overriding method can have a different throws clause as long as it doesn't declare any types not declared by the throws clause in the overridden method。 2、权限限定符,覆盖方法只能比被覆盖方法更多(the access specifier for the overriding method can allow more access than the overridden method, but not less.) 不能被覆盖的方法:final方法;static方法 必须被覆盖的方法:abstract方法 Being a descendent of Object   Method must be overrided clone Object里此方法的实现是先检查被clone的类是否实现了cloneable接口,没有丢出意外(注意:Object本身并没有实现cloneable clone不能调用new或者constructor,可以用super.clone equals/hashCode 两者必须一起被重写覆盖 finalize toString   Method cannot be overrided getClass 这是一个final方法,返回的是对象的类的运行时表示,返回一个Class对象;Class对象最常使用的就是编译阶段在不知道名字的情况下创建一个类的实例而在知道名字的情况下,可以从class名字得到一个Class对象,比如: String.class or Class.forName("String"); notify   notifyAll   wait Writing final classes and methods 在compiler和bytecode level都会提供对final的支持 使用final可能是因为security或者design的考虑 Writing abstract classes and methods  记住一点:abstract只能被继承,不能实例化 Implementing Nested Classes 当嵌套类(nested class)只有在被嵌套类(enclosing class)中才有意义或者它的功能依赖于被嵌套类时,嵌套类才应该被定义 类别:static nested class和inner class 区别:The term "nested class" reflects the syntactic relationship between two classes; that is, syntactically, the code for one class appears within the code of another. In contrast, the term "inner class" reflects the relationship between instances of the two classes. 事实上,nested class可以被定义在任何block当中 两个概念:adapter class和anonymous class

阅读全文(1802) | 回复(0) | 编辑 | 精华

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31

  公告
暂无公告...

  我的分类(专题)
  最近日志

  最新评论

  留言板

  链接

  Blog信息
blog名称:循环递归
日志总数:11
评论数量:6
留言数量:0
访问次数:60259
建立时间:2005年6月18日



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.162 second(s), page refreshed 144793479 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号