展开全部
/**
* 定义一个图形类
*
*/
public class Graph {
//图形的长高属性
public float length;
public float high;
public Graph(float length,float high) {
this.high = high;
this.length = length;
}
public float getArea(){
return 0;
}
}
/**
* 矩形的类
*
*/
public class Rectangle extends Graph{
public Rectangle(float length, float high) {
super(length, high);
}
public float getArea(){
float area = this.high * this.length;
return area;
}
}
/**
* 三角形的类
*
*/
public class Triangle extends Graph{
public Triangle(float length, float high) {
super(length, high);
}
public float getArea(){
float area = (float) (this.high * this.length * 0.5);
return area;
}
}
/**
* 主测试类
*
*/
public class MainTest {
public static void main(String[] args) {
Graph rectangle = new Rectangle(10, 5);
Graph triangle = new Triangle(10, 5);
System.out.println("矩形的面积是32313133353236313431303231363533e78988e69d8331333335336537:" + rectangle.getArea());
System.out.println("三角形的面积是:" + triangle.getArea());
}
}