Chapter 8 Inheritance and Polymorphism
          繼承和多態(tài)

          頭疼死了,不翻譯成中文了,直接摘書上提綱性的文字。

          1. A class C1 derived from another class C2 is called a subclass(extended class or derived class), and C2 is called a superclass(parent class or base class).
          Private data fields and methods in a superclass are not accessible outside of the class. Therefore, they are not inherited in a subclass.

          2. Keyword super
          (1) to call a superclass constructor
          (2) to call a superclass method
          The constructors of a superclass are not inherited in the subclass. They can only be invoked from the constructors of the subclasses, using the keyword super.
          In any case, constructing an instance of a class invokes the constructors of all the superclasses along the inheritance chain. This is called constructor chaining.
          If a class is designed to be extended, it is better to provide a no-arg constructor to avoid programming errors, since constructors of its subclass will defaultly invoke super()

          3. Overriding method (not overloading)
          To override a method, the method must be defined in the subclasss using the same signature and return type as in its superclass.
          A private method cannot be overridden, because it's not accessible outside its own class. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated.
          A static method can be inherited, but can't be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.

          4. The Object class
          Three frequently used methods:
          (1) public boolean equals(Object object)
          You should use equals(Object obj) to override the equals method in a subclass
          (2) public int hashCode()
          (3) public String toString()

          posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          1.28 Java notes

          Posted on 2007-04-22 20:23 ZelluX 閱讀(176) 評(píng)論(0)  編輯  收藏 所屬分類: OOP
          2007-01-28 23:15:12
          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 迁西县| 沂源县| 仙居县| 洛浦县| 平顺县| 英超| 禄丰县| 鸡西市| 永宁县| 桦川县| 崇州市| 苏尼特左旗| 丰顺县| 青河县| 曲松县| 平泉县| 修水县| 肥城市| 深泽县| 谢通门县| 陇南市| 象州县| 广饶县| 马边| 岑溪市| 大邑县| 扎兰屯市| 开鲁县| 乌苏市| 将乐县| 印江| 鸡西市| 麻栗坡县| 建瓯市| 营山县| 东兰县| 石河子市| 富蕴县| 普陀区| 老河口市| 大关县|