Understanding inheritance
What do you do when you have a class that does almost everything you need to get done? What do you do when you have methods in a class that don’t quite do what you need to get done? How do you deal with these two issues if you do not have access to the source code of the class and its methods? What if you do have access to the source code, but other parts of your program expect the original unchanged code? The answer is inheritance.
Inheritance is described as a relationship between two classes in which one class is called the superclass. This class contains the fields and methods to handle a specific task. This superclass is a generalization, and sometimes you need to enhance this kind of class. In this case, rather than rewriting the original class, you can create a new class called the subclass that inherits or specializes the superclass by overriding methods in the superclass or adding additional methods and fields. The subclass is now made up...