39 lines
783 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: typeinfo/Shapes.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
import java.util.*;
abstract class Shape {
void draw() { System.out.println(this + ".draw()"); }
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
abstract public String toString();
}
class Circle extends Shape {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public String toString() { return "Circle"; }
}
class Square extends Shape {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public String toString() { return "Square"; }
}
class Triangle extends Shape {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public String toString() { return "Triangle"; }
2015-05-18 23:05:20 -07:00
}
2015-04-20 15:36:01 -07:00
public class Shapes {
public static void main(String[] args) {
List<Shape> shapeList = Arrays.asList(
new Circle(), new Square(), new Triangle()
);
for(Shape shape : shapeList)
shape.draw();
}
} /* Output:
Circle.draw()
Square.draw()
Triangle.draw()
*///:~