package com.lxl.demo03;
/**
* 图形抽象类
* @author lxl
*
*/
public abstract class Graph {
public abstract double getArea();
}
package com.lxl.demo03;
/**
* 梯形类
* @author lxl
*
*/
public class Trapezoid extends Graph{
double top;
double bottom;
double height;
@Override
public double getArea() {
// TODO Auto-generated method stub
return (top+bottom)*height/2;
}
}
package com.lxl.demo03;
public class Test {
public static void main(String[] args) {
Trapezoid t = new Trapezoid();
t.top =2;
t.bottom =5;
t.height =3;
System.out.println("梯形的上底:"+t.top);
System.out.println("梯形的下底:"+t.bottom);
System.out.println("梯形的高:"+t.height);
System.out.println("梯形的面积:"+t.getArea());
}
}