Superclass Method Calls
Home ] Up ] An Example ] Points to Notice ] Constructor Chaining ] [ Superclass Method Calls ] Finalizer Chaining ]

 

 

Within any subclass method, the syntax:

super.method( /* arguments */ );

calls the appropriate method for the superclass.

We saw this in the Manager class's raiseSalary method when it called the Employee class's raiseSalary method.

    public void raiseSalary(double byPercent)
    {
        // Add 1/2% bonus for every year of service
        Date today = new Date();
        double bonus =
                0.5 * (today.getYear() + 1900 - getHireYear());
        super.raiseSalary(byPercent + bonus);
    }
Question: What would be the result of omitting the super. prefix, as in:
    public void raiseSalary(double byPercent)
    {
        // Add 1/2% bonus for every year of service
        Date today = new Date();
        double bonus =
                0.5 * (today.getYear() + 1900 - getHireYear());
        raiseSalary(byPercent + bonus);
    }

???

 

This page was last modified on 02 October, 2007