Java Inheritance ( IS-A relationship)

ref http://www.studytonight.com/java/inheritence-in-java.php

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

posted @ 2016-06-26 23:24  morningdew  阅读(239)  评论(0编辑  收藏  举报