Inheritances one of the cornerstones of object-oriented programming because it allow the creation of hierarchical classifications, Using inheritance, you can create a general class that defines traits common 10 a set of related items. This class can then be inherited by other, more specific classes, each adding those things that are unique to it, In the terminology of a is inherited is called a super class. The class that does the inheriting is called a Therefore, a subclass is a specialized version of a It inherits all of the instance variables and methods defined by the super class and adds its own, unique elements.
To inherit a class, you simply incorporate the definition of one class into r by . using the extends keyword. To see how, let’s begin with a short example. The following program creates a super class called A and a subclass called B. Notice how the keyword extends is used to create a subclass of A.
Even though A is a super class for n, it is also a completely independent, stand-alone class. Being a super class for a subclass does not mean that the super class cannot be used by itself. Further, a subclass can be a super class for another subclass. The general form of a class declaration that inherits a super class is shown here.
You can only specify one super class for any subclass that you create. lava does not ‘support the inheritance of multiple super classes into a single subclass. This differs from C++, in which you can inherit multiple base classes. You can, as stated, create a hierarchy of inheritance in which a subclass becomes a super class of another subclass. However, no class can be a super class of itself.