Question:

Define inheritance.

Show Hint

Think of inheritance in terms of genetics. A child inherits traits (like eye color) from their parents but can also have their own unique characteristics.
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Inheritance is a fundamental principle of Object-Oriented Programming (OOP). It is a mechanism where a new class (known as the `derived` or `child` class) acquires, or "inherits," the properties (data members) and behaviors (member functions) of an existing class (the `base` or `parent` class). The main purpose of inheritance is to promote code reusability. The derived class can use the functionality of the base class and can also add its own new features or override the existing ones. This creates an "is-a" relationship (e.g., a `Dog` is an `Animal`).
Was this answer helpful?
0
0