java接口和类的实验心得_实验八:接口与实现接口的类

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

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(); }

实验结果

33aa20a6fc5b494e14e4538ad2161121.png

实验心得:

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

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值