Introduction
Explore the concept of inheritance in D programming to create specialized subclasses from base classes. Understand how inheritance helps reduce code duplication by enabling subclasses to acquire members and behavior of superclasses. This lesson covers implementation inheritance with examples demonstrating class hierarchies and member access, preparing you to apply inheritance effectively in your D programs.
We'll cover the following...
Inheritance
Inheritance is defining a more specialized type based on an existing more general base type. The specialized type acquires the members of the base type and, as a result, can be substituted in place of the base type.
Inheritance is available for classes, not structs. The class that inherits another class is called the subclass, and the class that gets inherited is called the superclass, also called the base class.
There are two types of inheritance in D. We will cover the implementation of inheritance in this chapter and leave interface inheritance to a later chapter.
When defining a subclass, the superclass is specified after a colon character:
...