首页 > 其他 > 详细

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

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

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

package jiekou;
public class jiekou {

public static void main (String[] arges){

yuanzhui a=new yuanzhui(1,2,3);

yuanzhui b=new yuanzhui(4,5,6);

System.out.println(a.Area());

System.out.println(b.Area());

System.out.println(a.volume());

System.out.println(b.volume());

System.out.println("体积较大的是:"+Math.max(a.volume(), b.volume()));

}
}

class yuanzhui implements Volume,Area{

protected double r;

protected double l;

protected double h;

public yuanzhui(double r,double l,double h){

this.r=r; this.l=l; this.h=h;

}

public double volume(){

return Math.PI*Math.pow(r,2)*h/3;

}

public double Area(){

return Math.PI*this.r*this.r+this.r*this.l;
} }

interface Volume{ public double volume(); }

interface Area{ public double Area(); }

实验结果

技术分享图片

实验心得:

通过本次实验,明白了类的接口怎样应用,明白了接口的功能:Java接口是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为!

 

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

原文:https://www.cnblogs.com/wlyxjj/p/10896759.html

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