click below
click below
Normal Size Small Size show me how
OOP - L3
Forms of Inheritance
| Question | Answer |
|---|---|
| is an object-oriented programming OOP mechanism that allows one class (the subclass or child) to acquire the properties and behaviors of another class (the superclass or parent), promoting code reusability and extensibility. | Inheritance |
| Inheritance in object-oriented programming (OOP) comes in several forms | single, multiple, multilevel, hierarchical, and hybrid. |
| A subclass inherits from one parent class - Dog inherits from Animal. (animal - parent dog - child) | Single Inheritance |
| A subclass inherits from more than one parent class (supported in languages like C++, but not directly in Java). - FlyingCar inherits rom both Car and Airplane | Multiple Inheritance |
| A subclass inherits from more than one parent class supported in languages like C++, but not directly in Java). | Multiple Inheritance |
| a feature of an object-oriented concept, where a class can inherit properties of more than one parent class | Multiple Inheritance |
| - Like a contract - Any class which implements the interface must be able to do things inside the interfaces | Interfaces |
| Inside the Interface, you can create methods and data. | Multiple Inheritance using Interfaces |
| A chain of inheritance where a class is derived from another derived class - Grandparent → Parent → Child | Multilevel Inheritance |
| Multiple subclasses inherit from the same parent class. - Dog, Cat, and Cow all inherit from Animal | Hierarchical Inheritance |
| A combination of two or more types of inheritance often involving multiple and hierarchical). - A mix of hierarchical and multiple inheritance patterns | Hybrid Inheritance |
| is the simplest and most common, ensuring clarity and avoiding conflicts. | Single inheritance |
| can cause ambiguity (e.g., the "diamond problem"), which some languages solve using interfaces or virtual inheritance | Multiple inheritance |
| allows deeper hierarchies but can make systems harder to maintain if overused | Multilevel inheritance |
| is useful when multiple classes share common behavior | Hierarchical inheritance |
| is powerful but complex, often requiring careful design to avoid confusion | Hybrid inheritance |