Inheritance

From CSSEMediaWiki
Revision as of 23:10, 8 August 2009 by Matthew Harward (Talk | contribs)
Jump to: navigation, search

Inheritance is an OO concept that is designed to support code reuse by allowing classes within a program to extend or change the functionality of existing classes.

Example inheritance hierarchy

The Parent or Super Class is inherited from by the Subclass. All the public behaviour of the super class can be accessed through an instance of the subclass. In the example hierarchy class C also has the behaviour of duck and dive inherited from class A.

The process of Specialisation allows the subclass to add extra functionality by adding new methods. it also allows the subclass to change the functionality of inherited behaviour by overriding existing inherited methods with new ones. This is one form of polymorphism. In the example class B overrides the dive behaviour inherited from class A with its own 'dive method.


Personal tools