- Subclass
- Superclass
- Reusability
- Need for Inheritance
- Can OOP exist without Inheritance
- Inheritance types (Single, Multiple, Hierarchical, Multilevel, Hybrid, Virtual Inheritance)
- Real-life examples of Inheritance
- Limitation of Inheritance
- Sealed Modifier
- Object Slicing
1. Subclass
A subclass is a class that inherits from another class, known as the parent or base class. It is a way to create a new class that extends or specializes the behavior of an existing class.
Key Characteristics of a Subclass:
- Inheritance: A subclass inherits properties and methods from its parent class. This means it can use, modify, or extend the functionality provided by the parent class.
- Extension: A subclass can add new properties and methods that are not present in the parent class. It can also override existing methods to provide specialized behavior.
- Specialization: A subclass can provide more specific implementations or additional functionality based on the general behavior defined by the parent class.
Example in Swift
Here’s a simple example illustrating a subclass in Swift: