Java简单实训五
实训要求:
定义一个长方形类,使用继承得到长方体类,并计算表面积和体积。
代码实现:
class ChangShape{
protected int col;
protected int row;
public ChangShape(){}
public ChangShape(int col, int row){
this.col = col;
this.row = row;
}
public int getC(){
return 2*(this.col + this.row);
}
public int getS(){
return this.col*this.row;
}
}
class TiShape extends ChangShape{
protected int heigh;
public TiShape(){ super(); }
public TiShape(int col, int row,int heigh){
super(col, row);
this.heigh = heigh;
}
public int getS(){
return (this.col*this.row + this.col*this.heigh +this.row*this.heigh)*2;
}
public int getV(){
return this.col*this.heigh*this.row;
}
}
public class aaa{
public static void main(String [] args){
TiShape t = new TiShape(2,3,4);
System.out.println(t.getS());
System.out.println(t.getV());
}
}
转载请注明原文地址: https://ju.6miu.com/read-673129.html