Untitled
unknown
plain_text
2 years ago
1.1 kB
6
Indexable
class Shape {
public void draw() {
System.out.println("Drawing Shape");
}
public void erase() {
System.out.println("Erasing Shape");
}
}
class Circle extends Shape {
public void draw() {
System.out.println("Drawing Circle");
}
public void erase() {
System.out.println("Erasing Circle");
}
}
class Triangle extends Shape {
public void draw() {
System.out.println("Drawing Triangle");
}
public void erase() {
System.out.println("Erasing Triangle");
}
}
class Square extends Shape {
public void draw() {
System.out.println("Drawing Square");
}
public void erase() {
System.out.println("Erasing Square");
}
}
class PolymorphismExample {
public static void main(String[] args) {
Shape shape;
shape = new Circle();
shape.draw();
shape.erase();
shape = new Triangle();
shape.draw();
shape.erase();
shape = new Square();
shape.draw();
shape.erase();
}
}Editor is loading...