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


    1.源程序

    package jiekou;

    public class jiekou { public static void main (String[] arges)

    { yuanzhui a=new  yuanzhui(4,5,6);

    yuanzhui b=new  yuanzhui(7,8,9);

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

    }

    2.实验结果

    3.实验心得

        程序对我来说太困难了,还需要多多学习。以后还会重新进行调试,多多巩固。多向其他同学请教,把不会的努力掌握。

  • 相关阅读:
    [USACO08MAR]土地征用Land Acquisition
    树链剖分
    [AHOI2008]紧急集合 / 聚会
    P1852 [国家集训队]跳跳棋
    Ant Trip(欧拉回路+并查集)
    单词游戏
    POJ3694 Network
    C++ STL小总结
    2-Sat专题
    6大名家带你穿越大半个中国去深思
  • 原文地址:https://www.cnblogs.com/wzl55/p/10897080.html
Copyright © 2020-2023  润新知