展开全部
路径:
代码:
Shape.javapackage draw;
public class Shape {
public double getGirth(){
return 0;
}
public double getArea(){
return 0;
}
@32313133353236313431303231363533e78988e69d8331333332613761Override
public String toString() {
return "Shape [getGirth()=" + getGirth() + ", getArea()=" + getArea()
+ "]";
}
}
Rectangle.javapackage draw;
public class Rectangle extends Shape{
private double width;
private double height;
@Override
public double getGirth() {
return (width+height)*2;
}
@Override
public double getArea() {
return width*height;
}
@Override
public String toString() {
return super.toString();
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
Square,javapackage draw;
public class Square extends Shape {
private double side;
@Override
public double getGirth() {
return side*4;
}
@Override
public double getArea() {
return side*side;
}
@Override
public String toString() {
return super.toString();
}
public double getSide() {
return side;
}
public void setSide(double side) {
this.side = side;
}
}
text,javapackage draw;
public class tsest {
/**
* @param args
*/
public static void main(String[] args) {
Rectangle rec = new Rectangle();
rec.setHeight(10);
rec.setWidth(20);
System.out.println("矩形");
System.out.println(rec.toString());
Square squ = new Square();
squ.setSide(5);
System.out.println("正方形");
System.out.println(squ.toString());
}
}
测试结果: