Abstract Methods
Home ] Up ] [ Abstract Methods ] Abstract Classes ]

 

 

Let's imagine that we know that all employees will have a raiseSalary() method (else we wouldn't keep those employees very long!). However, it may well be that each class of employee has his or her salary raised using a different algorithm. We don't know what that algorithm is when we create the Employee class , but we know that every employee will have one.

We can define the raiseSalary() method on the Employee class, but not actually implement it there.

To do this, we have to declare the method abstract:

public abstract void raiseSalary(double byPercent);

In other words, an abstract method:

  • uses the abstract keyword, and
  • has a declaration, but no implementation.
 

This page was last modified on 02 October, 2007