Definition

Inheritance provides a way to create a new class from an existing class. The new class is a specialized version of the existing class such that it inherits all the public attributes (variables) and methods of the existing class. The existing class is used as a starting point or base to create the new class.

The IS-A relationship

After reading the definition above, the next question that comes to mind is, “when do we use inheritance?” Wherever we come across an IS-A relationship between objects, we can use inheritance.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.