5.3 Abstract classes
-
Change the declaration of your
Shapeclass as follows:1public abstract class Shape -
Change the methods
CalculatePerimeter()andCalculateArea()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.
-
Run your program. Since you have not changed the implementation, the output will be the same as in 5.2 Polymorphism.