码迷,mamicode.com
首页 > 其他好文 > 详细

实验八:接口与实现接口的类

时间:2019-05-20 22:58:20      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:使用   完成   ext   info   代码   多重   多重继承   main   double   

程序代码:

package shiyan;
interface Area
{
public abstract double area();
}
interface Volume
{
public abstract double volume();
}
public class yuanzhui extends Object implements Area,Volume
{
private double height;
private double raduis;
private double length;
public yuanzhui(double height,double raduis,double length)
{
this.height=height;
this.raduis=raduis;
this.length=length;
}
public double area()
{
return (Math.PI*this.raduis*this.length+Math.PI*this.raduis*2);
}
public double volume()
{
return this.height*Math.PI*this.raduis*2/3;
}
public static double max(yuanzhui X1,yuanzhui X2)
{
System.out.print("体积较大的圆锥为:");
if(X1.volume()>X2.volume())
return X1.volume();
else
return X2.volume();
}

public static void main(String[] args) {
yuanzhui YZ=new yuanzhui(1,4,6);
System.out.println("圆锥1的表面积为:"+YZ.area());
System.out.println("圆锥1的体积为:"+YZ.volume());
yuanzhui yz=new yuanzhui(2,6,1);
System.out.println("圆锥2的表面积为:"+yz.area());
System.out.println("圆锥2的体积为:"+yz.volume());
System.out.println("体积较大的圆锥为:"+Math.max(yz.volume(),YZ.volume()));
}
}

实验结果:

技术图片

实验心得:JAVA通过实验接口来弥补不支持多重继承的缺陷,为了声明一个接口,我们使用interface这个关键字。在实验中还有许多不懂得问题,不断调试后才完成的实验,以后还的多加调试程序。

实验八:接口与实现接口的类

标签:使用   完成   ext   info   代码   多重   多重继承   main   double   

原文地址:https://www.cnblogs.com/Java199-wfx/p/10896903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!