关闭

Important Points for Inheritance in Java

490人阅读 评论(0) 收藏 举报
分类:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:239965次
    • 积分:4623
    • 等级:
    • 排名:第6993名
    • 原创:212篇
    • 转载:33篇
    • 译文:8篇
    • 评论:125条
    最新评论