CSC/ECE 517 Fall 2010/ch2 2f EC: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<h1> What is inheritance? </h1> | <h1> What is inheritance? </h1> | ||
<p> | <p> | ||
Inheritance is a functionality of object-oriented programming where a subclass obtains the contents and functionality of its superclass. | <b>Inheritance</b> is a functionality of object-oriented programming where a subclass obtains the contents and functionality of its superclass. | ||
<br> | <br> | ||
Line 14: | Line 13: | ||
For example, if the class "Bike" already exists and we wanted to create specific type of bicycle such as "MountainBike" or "RoadBike", we could just create classes that inherit from the "Bike" class and add the additional functionality we need. | For example, if the class "Bike" already exists and we wanted to create specific type of bicycle such as "MountainBike" or "RoadBike", we could just create classes that inherit from the "Bike" class and add the additional functionality we need. | ||
<br> | |||
<br> | |||
[[Image:EC_fig1.jpg]] | |||
<br> | |||
Figure 1: Simple case of inheritance | |||
<br> | |||
<br> |
Revision as of 19:20, 21 September 2010
What is inheritance?
Inheritance is a functionality of object-oriented programming where a subclass obtains the contents and functionality of its superclass.
Instead of duplicating a class, a user can create a class that is a subclass of another class, inherit all of its functionality, and just add additional functionality.
For example, if the class "Bike" already exists and we wanted to create specific type of bicycle such as "MountainBike" or "RoadBike", we could just create classes that inherit from the "Bike" class and add the additional functionality we need.
Figure 1: Simple case of inheritance