A derived Java class can call a constructor in its base class using the
super keyword. In fact, a constructor in the derived class must call the
super's constructor unless default constructors are in place for both classes.
To understand how to use the super keyword to call a base class constructor, follow these 10 steps.
lastName. Notice that the program follows the Javabean specification for defining a property, i.e., a private variable with getter and setter methods. Also note that the constructor requires two parameters, the first name and the last name.
Employeeclass defines one property,
empId. This property will contain the employee ID. Notice that the constructor in this class calls the constructor in the super class (
Person). The first name and last name parameters are passed to the constructor.
getLastNamemethods. The first name and last name parameters have been passed to the base constructor by the derived class constructor. The program also calls the
getEmpIdmethod in the Employee object.