You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0 KiB

package Shape;
abstract public class Shape {
abstract void draw();
}
class Circle extends Shape{
private double r;
public Circle(double r){
this.r=r;
}
@Override
public void draw(){
System.out.println("已绘制半径为"+r+"的圆");
}
}
class Rectangle extends Shape{
private double chang;
private double kuan;
public Rectangle(double chang,double kuan){
this.chang=chang;
this.kuan=kuan;
}
@Override
public void draw(){
System.out.println("已绘制长宽分别为"+chang+"和"+kuan+"的矩形");
}
}
class Triangle extends Shape{
private double di;
private double height;
public Triangle(double di,double height){
this.di=di;
this.height=height;
}
@Override
public void draw(){
System.out.println("已绘制底和高分别为"+di+"和"+height+"的三角形");
}
}
class ShapeUtil{
public static void drawShape(Shape s){
s.draw();
}
}