接口类
* 接口:形状
*/
public interface Shape {
* 获取体积
*
* @return 形状的体积
*/
int getArea();
* 获取名称
*/
String getName();
}
实现类 Rectangle
* 矩形
*/
public class Rectangle implements Shape {
private static final String TAG = "矩形";
private int width;
private int length;
public Rectangle(int width, int length) {
this.width = width;
this.length = length;
}
@Override
public int getArea() {
return width * length;
}
@Override
public String getName() {
return TAG;
}
}
实现类 Square
* 正方形
*/
public class Square extends Rectangle {
private static final String TAG = "正方形";
public Square(int length) {
super(length, length);
}
@Override
public String getName() {
return TAG;
}
}