Monthly Archives: May 2022

5.1 Implementing Inheritance Inheritance is one of the fundamental mechanisms for code reuse in OOP. It allows new classes to be derived from existing ones. The new class (also called a subclass, subtype, derived class, or child class) can inherit members from the old class (also called a superclass, supertype, base class, or parent class). The subclass can add new behavior and properties and, under certain circumstances, modify its inherited behavior. A subclass specifies the name of its superclass in the subclass header using the extends clause. Click here to view code image class TubeLight extends Light { … }   // TubeLight is a subclass of Light. The subclass specifies only the additional new and modified members in its class body. The rest of its declaration is made up of its inherited members. If no extends clause is specified in the header of a class declaration, the class implicitly inherits…

Read more

1/1