A derived class is a Java class that inherits properties from its super class. For example, an
Employee class might be derived from a
Person class. Therefore the
Employee class could inherit first name and last name properties from
Person, its super class. The following eight steps show how to write a derived class in Java.
fullName. This property will contain first name and last name. Notice that the program follows the Javabean specification for defining a property, i.e., a private variable with getter and setter methods.
Employeeclass defines one property:
empId. This property will contain the employee ID. Notice that the constructor calls the constructor in the super class (
Person). The full name parameter is passed to the constructor.
getFullNamemethod. This method is located in the
Personclass. The method can be called from the Employee object, verifying that derived classes inherit super class methods.