Interview Questions, Answers and Tutorials

Category: Inheritance

12 Inheritance

Inheritance is a mechanism that allows classes to inherit the attributes of an existing class. It is used in situations where the subclass (which inherit attributes) is a subset of the superclass, whose attributes are Inherited. For example, suppose there are three classes of employee, developer, and tester. In this case, both developers and testers are employees. Here, the employee class can define generic attributes of employees. Specific attributes of developers can be defined in the developer class, while specific attributes of testers can be defined in the tester class. Both developer and tester are subclasses while an employee is…