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.
22 lines
528 B
22 lines
528 B
package com.shape;
|
|
|
|
/**
|
|
* 抽象类 Shape
|
|
* 提供统一的面积计算接口
|
|
*/
|
|
public abstract class Shape {
|
|
|
|
/**
|
|
* 抽象方法:计算图形面积
|
|
* 子类必须实现该方法
|
|
* @return 图形的面积(double类型)
|
|
*/
|
|
public abstract double getArea();
|
|
|
|
/**
|
|
* 通用方法:打印图形信息(可选,方便扩展)
|
|
*/
|
|
public void display() {
|
|
System.out.println(this.getClass().getSimpleName() + " 的面积为: " + getArea());
|
|
}
|
|
}
|