class Polygon//多边形
{
double width;//正方形
double height;//正方形高
double getArea()
{
double area = width*height;
return area;
}
}
class Cube//立方体
{
double length;
double width;
double hight;
double getArea() {
double area = (length*width+length*hight+width*hight)*2;
return area;
}
double getVolume(){
double volume = length*width*hight;
return volume;
}
}
public class Example {
public static void main(String[] args) {
// TODO Auto-generated method stub
Polygon square;//声明对象
square = new Polygon();//为对象分配变量
square.width = 100.98;
square.height = 10.87;
double area = square.getArea();
System.out.println("正方形的面积:"+area);
Cube cube;
cube = new Cube();
cube.length = 20.56;
cube.width = 7.44;
cube.hight = 13.55;
area = cube.getArea();
System.out.println("正方体的面积:"+area);
double volume = cube.getVolume();
System.out.println("正方体的体积:"+volume);
}
}