首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

种的多态接口与抽象类的练习

2012-07-19 
类的多态接口与抽象类的练习interface Tiji{public abstract void meng()}abstract class Chenchen {abst

类的多态接口与抽象类的练习
interface Tiji{
public abstract void meng();
}
abstract class Chenchen {

    abstract double getS();
    abstract double getV();
    void printSV(){
    System.out.println("表面积:"+getS());
    }
   
}
class Diandian extends Chenchen implements Tiji{
double r,h;
Diandian(double x,double y){r=x;h=y;}
double getS(){return 2*(Math.PI*r*r)+(2*Math.PI*r*h);}
double getV(){return Math.PI*r*r*h;}
public  void meng(){
System.out.println("圆柱体积:"+getV());
}
}


class Chen extends Chenchen implements Tiji{

double a,b,h;
public Chen(double x,double y,double z){

a=x;
b=y;
h=z;
}
double getS(){return 2*(a*b+a*h+h*b);}
double getV(){return a*b*h;}
public  void meng(){
System.out.println("长方体体积:"+getV());
}
}

public class homework{
public static void main (String[] args) {
Chenchen s=new Diandian(3,4);
s.printSV();
Tiji s1=new Diandian(3,4);
s1.meng();
Chenchen c1=new Chen(5,6,7);
c1.printSV();
Tiji c2=new Chen(5,6,7);
c2.meng();
}
}

热点排行