Inheritance is concerned with the relationship between two classes—the base class and the derived class. In this section we will cover the following:
Implementing a subclass
Using the
protected
keywordOverriding methods
Using the
@Override
annotationUsing the
final
keyword with classesCreating abstract methods and classes
The use of constructors and inheritance is covered in the The super keyword and constructors section.
When inheritance occurs, the derived class inherits all of the methods and attributes of the base class. However, it can only access the public and protected members of the class. It cannot access the private members of the class.
When a method is added to a derived class that has the same signature and accessibility of a base class method, the method is said to override the base class method. This allows the derived class to redefine the meaning of that method. The examples in this chapter will use a Employee
base class and a SalaryEmployee
class that is derived...