Java Inheritance ( IS-A relationship)

Posted morningdew

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java Inheritance ( IS-A relationship)相关的知识,希望对你有一定的参考价值。

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)的主要内容,如果未能解决你的问题,请参考以下文章

Java核心技术第四章----对象与类重难点总结

2017/8/4 SCJP学习

深入理解Java的继承特性

JAVA基础——is-a have-a和 like-a的区别

Java千百问_05面向对象(006)_is-a,has-a,like-a是什么

is-a have-a和 like-a的区别