class Graph{
public double getArea(){
return 0;}
public double getGirth(){
return 0;}
}
class Circle extends Graph{
public static final double PI=3.14;
public double r;
Circle(double r){
this.r=r;
}
public double getArea(){
return PI*r*r;
}
public double getGirth(){
return 2*PI*r;
}
}
class Trigon extends Graph{
public double a;public double b;
public double c;
Trigon(double a,double b,double c){
this.a=a;
this.b=b;
this.c=c;
}
public double getArea(){
double s,p;
p=(a+b+c)/2;
s=Math.sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
public double getGirth(){
return a+b+c;
}
}
class GraphTest{
public static void main(String[]args){
Graph m=new Trigon(3,4,5);
System.out.println(m.getGirth());
System.out.println(m.getArea());
}
}作者: 黑马-文鸿利 时间: 2013-8-23 15:16
/抽象的形状类
public abstract class Shape{ }