- public interface Area{ //定义接口
- public abstract double getArea();
- }
- class Ellipse implements Area{ //定义类
- double r1,r2; // 定义两个半径
- public Ellipse(double a, double b){ //构造方法
- r1=a; r2=b;
- }
- public double getArea(){
- double mj=...a...b...; //椭圆面积计算公式你自己写
- return mj;
- }
- public static void main(String[] args) {
- Ellipse e1=new Ellipse(10,20);
- System.out.print(e1.getArea());
- }
- }
复制代码 |