实验程序为:
package 父类子类;
interface Area
{
public abstract double area();
}
interface Volume
{
public abstract double volume();
}
public class yuanzhui extends Object implements Area,Volume
{
public int height;
public int raduis;
public int length;
public yuanzhui(int height,int raduis,int length)
{
this.height=height;
this.raduis=raduis;
this.length=length;
}
public double area()
{
return (Math.PI*raduis*length+Math.PI*raduis*2);
}
public double volume()
{
return height*Math.PI*raduis*2/3;
}
public static double max(yuanzhui X,yuanzhui Y)
{
System.out.print("体积较大圆锥体体积为:");
if(X.volume()>Y.volume())
return X.volume();
else
return Y.volume();
}
public static void main(String[] args) {
yuanzhui YZ=new yuanzhui(3,4,5);
System.out.println("圆锥表面积为:"+YZ.area());
System.out.println("圆锥体积为:"+YZ.volume());
yuanzhui yz=new yuanzhui(4,5,6);
System.out.println("圆锥表面积为:"+yz.area());
System.out.println("圆锥体积为:"+yz.volume());
System.out.println("圆锥体积较大的为:"+Math.max(yz.volume(),YZ.volume()));
}
}
实验结果为:
实验心得:
1.初步认识和了解了接口的使用和接口的作用。
2.写程序时,还是遇到了一些问题,但是最后经过不断的调试,大体上还是完成了程序。