java 超类问题

来源:百度知道 编辑:UC知道 时间:2024/05/28 03:37:54
编写出能够想象到的形状,包括二维和三维图形,将这些形
状组成一个形状层次。层次中应有超类Shape,然后从Shape
派生出TwoDimensionalShape和ThreeDimensionalShape类
。一旦建成了该层次,就定义层次中的各个类。

/*
* 编写出能够想象到的形状,包括二维和三维图形,将这些形
* 状组成一个形状层次。层次中应有超类Shape,然后从Shape
* 派生出TwoDimensionalShape和ThreeDimensionalShape类
* 一旦建成了该层次,就定义层次中的各个类。
*/
interface Shape{
int getHeight();
void setHeight(int x);
int getWidth();
void setWidth(int y);
}

class TwoDimensionalShape implements Shape{
private height;
private width;

TwoDimensionalShape(){}
TwoDimensionalShape(int x, int y){
this.height = x;
this.width = y;
}
public void setHeight(int x){
this.height = x;
}
public void setWidht(int y){
this.width = y;
}
public int getHeight(){
return height;
}
public int getWidth(){
return width;
}
private int getArea(){
return height * width;
}
}

class ThreeDim