Inheritance in Java
A class that is used as a basis for inheritance, such as Employee, is a base class. When you create a class that inherits from a base class (such as EmployeeWithTerritory), it is a derived class. When considering two classes that inherit from each other, you can tell which is the base class and which is the derived class by using the two classes in a sentence with the phrase “is a(n).” A derived class always “is a” case or example of the more general base class. For example, a Tree class can be a base class to an Evergreen class. An Evergreen “is a” Tree, so Tree is the base class; however, it is not true for all Treees that “a Tree is an Evergreen.
Similarly, an EmployeeWithTerritory “is an” Employee-but not the other way around –so Employee is the base class. You can use the terms superclass and subclass as synonyms for base class and derived class, respectively. Also use the terms parent class and child class.
When a parent class contains a method that is not overridden within its child, the child can use the method name with super (because the method is a member of the superclass), with this(because the method is a member of the subclass by virtue of inheritance), or alone(again, because the method is a member of the subclass).
The three types of methods that you cannot override in a subclass are:
Static methods
Final methods
Methods within final classes
Programmers of an abstract class can include two method types:
Nonabstract methods, like those you can create in any class, are implemented in the abstract class and are simply inherited by its children.
Abstract methods have no body and must be implemented in child classes.
When a superclass is abstract, you cannot instantiate objects of the superclass; however, you can indirectly create a reference to a superclass abstract object. A reference is not an object, but it points to a memory address. When you create a reference, you do not us ethe keyword new to create a concrete object; instead, you create a variable name in which you can hold the memory address of a concrete object. So, although a reference to an abstract superclass object is not concrete, you can store a concrete subclass object reference there.