Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

13: Inheritance

( \newcommand{\kernel}{\mathrm{null}\,}\)

  • 13.0: Introduction
    This page explains inheritance in object-oriented programming, highlighting how it creates relationships between classes by allowing a class to be a subtype of another. This mechanism enables classes to inherit attributes and methods, reducing redundancy and promoting modularity in code design.
  • 13.1: Inheritance Basics
    This page outlines learning objectives regarding class relationships in programming, emphasizing is-a and has-a relationships, subclasses, superclasses, and inheritance in Python. It includes examples, such as a Daffodil class as a subclass of Plant, and offers practice checkpoints for identifying relationships and creating subclasses. The text also clarifies terminology and concludes with practical exercises to solidify understanding.
  • 13.2: Attribute Access
    This page outlines learning objectives for implementing subclasses in Python, detailing how they can inherit attributes from superclasses and define instance attributes in their `__init__()` method. It includes examples of subclass creation, attribute access, and display method modification. The page also offers practical exercises that encourage readers to apply these concepts, specifically through the Dessert and Cupcake example.
  • 13.3: Methods
    This page discusses learning objectives for method overriding, the `super()` function, and polymorphism in programming. It details how subclasses can alter inherited methods and utilize `super()` to access superclass functions, supported by examples and hypothetical class structures. It also features practice questions and tasks designed to enhance comprehension of these key programming principles.
  • 13.4: Hierarchical Inheritance
    This page outlines learning objectives on hierarchical inheritance in programming, detailing its concept where multiple classes derive from one superclass. It provides examples of creating organized class structures, specific code illustrations, checkpoint questions for comprehension, and a coding exercise for practical application involving class definitions with attributes and inheritance.
  • 13.5: Multiple Inheritance and Mixin Classes
    This page outlines learning objectives on multiple inheritance in programming, detailing its benefits and issues such as the diamond problem. It introduces mixin classes to resolve inheritance conflicts, provides class definition examples, and emphasizes code enhancement through mixins. Practical exercises are encouraged to solidify understanding of these concepts.
  • 13.6: Chapter Summary
    This page covers inheritance in object-oriented programming, focusing on the is-a relationship, subclass attributes and methods, method overriding, and the use of `super()`. It introduces polymorphism, hierarchical and multiple inheritance, and mixin classes. The chapter concludes by guiding readers on creating subclasses with distinct traits and overridden methods within different inheritance frameworks.


This page titled 13: Inheritance is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by OpenStax via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?