首页 > 编程语言 > 详细

Important Points for Inheritance in Java

时间:2015-07-06 17:55:11      阅读:213      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!