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.

31 lines
636 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package jichuti;
/**
* 正方形类实现Shape接口
*/
public class Square implements Shape {
private String color; // 颜色
private double side; // 边长
public Square(String color, double side) {
this.color = color;
this.side = side;
}
@Override
public String getColor() {
return color;
}
@Override
public double getArea() {
return side * side; // 正方形面积=边长×边长
}
// getter和setter
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
}