10.6 Summary

We have introduced the notion of object inheritance and shown some examples.

10.6.1 Key Concepts

  • One of the most powerful tools in object-oriented programming (OOP) is that objects can be created from other objects and use the resources of the parent object. This is known as inheritance. In this relationship, the parent class or superclass defines the relationship with the child class or subclass.

  • Subclasses inherit both data and methods from their parent class.

  • A key point to keep in mind when working with inheritance is that polymorphism often takes place, which in some cases can lead to a need for method overriding.

10.6.2 Key Definitions

  • Inheritance: When the relationship between two classes is defined.

  • Superclass: The class that defines the object for the relationship.

  • Subclass: The class for which the relationship is defined.

  • Method overriding: When the method for a parent class is redefined for a child class.

  • Polymorphism: Allows different data types to be handled by a unified interface.

Get Computer Science Programming Basics in Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.