Important Points for Inheritance in Java
1.Private members of superclass are not directly accessible to subclass. As in this example, Animal variable noOfLegs is not accessible to Cat class but it can be indirectly accessible via getter and setter methods.
2.Superclass members with default access is accessible to subclass ONLY if they are in same package.
3.Superclass constructors are not inherited by subclass.
4.If superclass doesn’t have default constructor, then subclass also needs to have an explicit constructor defined. Else it will throw compile time exception.
5.Java doesn’t support multiple inheritance, a subclass can extends only one class. So here Animal is implicitly extending Object class and Cat is extending Animal class but due to java inheritance transitive nature, Cat class also extends Object class.
摘自:http://www.journaldev.com/644/inheritance-in-java-example
相關文章
- Important points about LOGGING and NOLOGGING(轉)Import
- Max Points on a Line leetcode javaLeetCodeJava
- case class inheritance
- javascript Classical InheritanceJavaScript
- [Relationships]Inheritance
- CSS !importantCSSImport
- An important personImport
- 說說Prototypal Inheritance
- Important directory for OBIEE 11g for system component and java componentImportJava
- 修改important樣式Import
- very important -have a LookImport
- !important 什麼意思?Import
- Writing on important detailsImportAI
- A Person Who Is Important to MeImport
- Machine Learning - Basic pointsMac
- Objects as Points 論文總結Object
- Restore Points 制定回退方案REST
- Important SAP APO Function Modules!ImportFunction
- css中!important的作用CSSImport
- What are Windows ACLs and why are they important?WindowsImport
- Important Transaction Codes For BWImport
- Entity Framework Code-First(7):Inheritance StrategyFramework
- Leetcode Max Points on a LineLeetCode
- Points on Cycle (hdu1700,幾何)
- CF 295E Yaroslav and Points(Splay)ROS
- Game with points(數學,難度中)GAM
- 一張圖看懂CSS cascade, specific, importance, inheritanceCSSImport
- !important------至高無上的寶劍Import
- Various Important SAP Basis T-CodeImport
- IE6也認識!importantImport
- guarantee restore points-Flashback after RMAN restoreREST
- Leetcode-Max Points on a LineLeetCode
- Caused by: java.lang.IllegalStateException: Only single-level inheritance supported: XxxxServiceJavaException
- odoo 開發入門教程系列-繼承(Inheritance)Odoo繼承
- Inheritance with EF Code First: Part 1 – Table per Hierarchy (TPH)
- Inheritance with EF Code First: Part 2 – Table per Type (TPT)
- virtual inheritance 的妙用--------實現final類 (轉)
- SAP Important note on transporting tax codesImport