Inheritance and Composition — Java

Inheritance is a mechanism in which a new class (subclass or derived class) is created by inheriting the properties and behaviors of an…