Shape Class
Create the Shape class with the following properties :
- The class should be abstract
-
Create two instance variables of type int and one instance variable of type PApplet.
Make sure all these three instance variables are private. The first two variables will represent the x and y coordinates of a shape. The third variable will represent the canvas onto which we will be drawing our shape. -
Create a constructor taking x and y coordinates and the canvas as parameters.
The constructor should initialize all instance variables to the parameter values.
- Create accessor methods for each coordinate of the shape and the PApplet variable.
-
Create an abstract method declaration draw to draw the corresponding shape.
Why is this method defined as abstract?
NOTE:
An abstract method contains only the method declaration, followed by a semicolon (;).
A class should be declared abstract even if it only contains one abstract method
public abstract class Shape { ... public abstract void draw(); ... }
A method should be declared abstract if the class in which it is declared is too general or abstract for it to have a definition.
A class that is this general isn't something we'd ever want to instantiate as it merely serves as a base class with some possible common behavior or attributes from which to derive more concrete classes.
In fact, you cannot instantiate or create an object that has an abstract method. What would happen if this was possible and you called an abstract method? There would be no definition or code to execute for that call.