Friday, October 28, 2016

Java - Inheritance



Inheritance defines a relationship between objects that share characteristics. Specifically, it is the mechanism whereby a new class, called a subclass, is created from an existing class, called a superclass, by absorbing its state and behavior and augmenting these with features unique to the new class. We say that the subclass inherits characteristics of its superclass.

Inheritance provides an effective mechanism for code reuse. Suppose the code for a superclass has been tested and debugged. Since a subclass object shares features of a superclass object, the only new code required is for the additional characteristics of the subclass.


A subclass can itself be a superclass for another subclass, leading to an inheritance hierarchy of classes. For example, consider the relationship between these objects: Cup, CoffeeCup, TeaCup, CoffeeMug, and EspressoCup. In the picture, the arrow designates the is-a relationship. A CoffeeCup is-a Cup; a TeaCup is-a Cup; a CoffeeMug is-a CoffeeCup; an EspressoCup is-a CoffeeCup. However, notice that the opposite is not necessarily true: A Cup may not be a CoffeeCup, nor is a CoffeeCup necessarily an EspressoCup.

---------------------------------------------------------------------------------

Writing References:
1.Barron's AP Computer Science A
Picture References:
1.https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP_YuplNf7OOSBMCU7FRKHXzYAxY8bllMqYAxCRt_vTFBDeZjX7cSRboJSN9XEIzY2xFfhdeh23h8xAsKlajumMBCLOOcsBnO8-0tFJc8VH6yv126lItwYg5kJsaiSCNWcuACI1UELRTc/s1600/OOP+-+Inheritance.jpg
2.http://www.artima.com/objectsandjava/webuscript/images/inheFig1.gif