Inheritance

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
Line 5: Line 5:
 
The process of '''Specialisation'''  
 
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.
 
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.
 +
 +
== See Also ==
 +
* [[Superclass]]
 +
* [[Subclass]]
  
 
{{Nomenclature}}
 
{{Nomenclature}}
  
 
[[Category: Nomenclature]]
 
[[Category: Nomenclature]]

Revision as of 22:17, 16 September 2009

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.

See Also


Personal tools