13-4
class Figure {
double x;
double y;
String color;
public Figure(double x, double y, String color) {
this.x = x;
this.y = y;
this.color = color;
}
}
class Circle extends Figure {
double r;
public Circle(double x, double y, double r, String color) {
super(x, y, color);
this.r = r;
}
public void printout() {
System.out.printf("%f %f %f %s¥n", this.x, this.y, this.r, this.color);
}
}
class Rectangle extends Figure {
double width;
double height;
public Rectangle(double x, double y, double w, double h, String color) {
super(x, y, color);
this.width = w;
this.height = h;
}
public void printout() {
System.out.printf("%f %f %f %f %s", this.x, this.y, this.width, this.height, this.color);
}
}
public class YourClassNameHere {
public static void main(String[] args) {
Circle x = new Circle(2, 4, 3, "green");
Rectangle a = new Rectangle(6, 4, 1, 2, "blue");
x.printout();
a.printout();
}
}
67