Polymorphism(多态)

  • Override: a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

  • Polymorphism:A call to a member function will cause a different function to be executed depending on the type of object that invokes the function.(subtype polymorphism)

public class Programmer extends Employee {
    // ...

    @Override
    public int calculateSalary(double performanceScore) {
    return (int)(getBaseSalary(level)*(1.5(performanceScore);
    }
}

Employee e1 = new Programmer(...);
e1.calculateSalary(0.95);
Employee e2 = new Manager(...);
e2.calculateSalary(0.85);

results matching ""

    No results matching ""