Inheritance

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: 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. [[Image:Inheritance.jpg|...)
 
m
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
 
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.
 
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.
 
[[Image:Inheritance.jpg|frame|Example inheritance hierarchy]]
 
[[Image:Inheritance.jpg|frame|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 '''Parent''' or '''[[Superclass|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'''  
 
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]]
 +
* [[Class versus Object]]
 +
 +
{{Nomenclature}}
 +
 +
[[Category: Nomenclature]]

Latest revision as of 22:19, 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