Skip to content

5.3 Abstract classes

  1. Change the declaration of your Shape class as follows:

    1
    public abstract class Shape
    
  2. Change the methods CalculatePerimeter() and CalculateArea() as follows:

    1
    2
    public abstract double CalculatePerimeter();
    public abstract double CalculateArea();
    
    • Note that both methods have no body. They are only declared here.
    • The implementation of the methods happens in the derived classes.

    You can only define new derived classes from an abstract class if you override the abstract methods in those derived classes.

  3. Run your program. Since you have not changed the implementation, the output will be the same as in 5.2 Polymorphism.