zoukankan      html  css  js  c++  java
  • 实验八:接口与实现接口的类

    程序代码:

    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这个关键字。在实验中还有许多不懂得问题,不断调试后才完成的实验,以后还的多加调试程序。

  • 相关阅读:
    Shiro结合配置文件实战实现权限验证
    Shiro的一些概念解释以及配置了解
    jedis工具类
    【转载】redis的主从复制
    Redis的事务
    redis的持久化
    SSM框架-SpringMVC 实例文件上传下载
    如何设置CentOS 7获取动态及静态IP地址
    阿里云linux centos 一键部署web环境--图文详解
    SVN使用教程总结
  • 原文地址:https://www.cnblogs.com/Java199-wfx/p/10896903.html
Copyright © 2011-2022 走看看