码迷,mamicode.com
首页 > 编程语言 > 详细

Important Points for Inheritance in Java

时间:2015-07-06 17:56:02      阅读:160      评论:0      收藏: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

版权声明:本文为博主原创文章,未经博主允许不得转载。

Important Points for Inheritance in Java

标签:

原文地址:http://blog.csdn.net/leochang130731/article/details/46776243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!