首页 > 编程语言 > 详细

Java Inheritance ( IS-A relationship)

时间:2016-06-26 23:49:08      阅读:193      评论:0      收藏:0      [点我收藏+]

Inheritance (IS-A)

when a class extends another another class it inherits all non private members including fields and methods. Inheritence in Java can be 

best understood in terms of Parent and child relationship. also known as Super class and Sub class.

 

Inheritence is a IS-A relationship. like car extends vehicle cos car IS-A vehicle

 

Super class reference pointing to Sub class object.

In context where class B extends class A

A a = new B(); 

is legal syntax because of IS-A relationship

 

Q. Can you use both this() and super() in a Constructor?

No, because both super() and this() must be the first statement inside a constractor. Hence we cannot use them together

Java Inheritance ( IS-A relationship)

原文:http://www.cnblogs.com/morningdew/p/5618866.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!