首页 > 其他 > 详细

实验8

时间:2019-05-20 10:15:43      阅读:103      评论:0      收藏:0      [点我收藏+]

1.程序步骤

package 项目;
interface Area
{
public abstract double area();
}
interface Volume
{
public abstract double volume();
}
public class yuanzhui extends Object implements Area,Volume
{
int height,raduis,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);
yuanzhui yz=new yuanzhui(4,5,6);
System.out.println("圆锥1表面积为:"+YZ.area());
System.out.println("圆锥2表面积为:"+yz.area());
System.out.println("圆锥1体积为:"+YZ.volume());
System.out.println("圆锥2体积为:"+yz.volume());
System.out.println("圆锥体积较大的为:"+Math.max(yz.volume(),YZ.volume()));
}
}

2.心得体会

java中的接口是为了弥补java单继承的特性,因为java中的类只能单继承,接口和接口之间可以多继承,一个类也可以实现多个接口  , 接口还有一个功能,是用来解耦合。接口之间可以存在多继承,中间以  , 隔开   一个类可以实现多个接口  。  接口中的抽象方法public abstract 可以省略。

实验8

原文:https://www.cnblogs.com/yanqianying1/p/10892001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!