Create an abstract class called figure which has an abstract method called draw().
Make the subclasses called Filled_Rectangle, Filled_Arc and override the draw()
function in which you would just print the message regarding the current object.
abstract class Figure {
abstract void draw();
}
class Filled_Rectangle extends Figure {
void draw() {
System.out.println("Filled Rectangle");
}
}
class Filled_Arc extends Figure {
void draw() {
System.out.println("Filled Arc");
}
}
class App {
public static void main(String[] args) {
Figure figure = new Filled_Rectangle();
figure.draw();
figure = new Filled_Arc();
figure.draw();
}
}
Comments
Leave a comment