Skip to main content Accessibility help
×
Hostname: page-component-8448b6f56d-c47g7 Total loading time: 0 Render date: 2024-04-23T19:59:29.533Z Has data issue: false hasContentIssue false

Six - Inheritance and Polymorphism

Published online by Cambridge University Press:  15 October 2009

Ed Akin
Affiliation:
Rice University, Houston
Get access

Summary

Introduction

As we saw earlier in our introduction to OOP, inheritance is a mechanism for deriving a new class from an older base class. That is, the base class, sometimes called the super class, is supplemented or selectively altered to create the new derived class. Inheritance provides a powerful code reuse mechanism since a hierarchy of related classes can be created that share the same code. A class can be derived from an existing base class using the module construct illustrated in Figure 6.1.

We note that the inheritance is invoked by the USE statement. Sometimes an inherited entity (attribute or member) needs to be slightly amended for the purposes of the new classes. Thus, at times one may want to bring into the new class selectively only certain entities from the base class. The modifier ONLY in a USE statement allows one to select the desired entities from the base class as illustrated in Figure 6.2. It is also common to develop name conflicts when combining entities from one or more related classes. Thus, a rename modifier, =>, is also provided for a USE statement to allow the programmer to pick a new local name for an entity inherited from the base class. The form for that modifier is given in Figure 6.3.

It is logical to extend any or all of the aforementioned inheritance mechanisms to produce multiple inheritance. Multiple Inheritance allows a derived class to be created by using inheritance from more than a single base class.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2003

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Inheritance and Polymorphism
  • Ed Akin, Rice University, Houston
  • Book: Object-Oriented Programming via Fortran 90/95
  • Online publication: 15 October 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511530111.007
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Inheritance and Polymorphism
  • Ed Akin, Rice University, Houston
  • Book: Object-Oriented Programming via Fortran 90/95
  • Online publication: 15 October 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511530111.007
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Inheritance and Polymorphism
  • Ed Akin, Rice University, Houston
  • Book: Object-Oriented Programming via Fortran 90/95
  • Online publication: 15 October 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511530111.007
Available formats
×