java接口相关习题

interface Graphics
{  //接口里面只能用抽象方法
  public abstract double area();
    }
//设置 平面类
class PlaneGraphics1
{
    private String shape; //形状
    //构造方法,有参数
    public PlaneGraphics1(String shape)
    {
        this.shape=shape;
    }
    //无参数
    public PlaneGraphics1()
    {
        this("未知图形1");
    }
    //打印
    public void print()
    {
        
    }
    
    }
//长方形 ,继承接口必要实现接口的抽象方法,不然会报错的。
class Rectangle extends PlaneGraphics1 implements Graphics
{
    protected  double length;
    protected double width;
    //构造方法
    public Rectangle(double length,double width)
    {
        this.length=length;
        this.width=width;
    }
    //正方形构造方法
    public Rectangle(double width)
    {
        this.length=width;
        this.width=width;
    }
    //无参数构造方法
    public Rectangle()
    {
        
    }
    public   double area()
    {
        return width*length;
    }
    public void print()
    {
        System.out.println("长方形面积为:"+this.area());
    }
    
    }
//椭圆
class Eclipse extends PlaneGraphics1 implements Graphics
{
    protected  double radius_a;
    protected double radius_b;
    //椭圆构造方法
    public Eclipse(double radius_a,double radius_b)
    {  
        super("椭圆");
        this.radius_a=radius_a;
        this.radius_b=radius_b;
        
    }
    //圆
    public Eclipse(double radius_a)
    {
        super("圆");
        this.radius_a=radius_a;
        this.radius_b=radius_a;
    }
    public Eclipse()
    {
        
    }
     public double area()
     {
         return Math.PI*radius_a*radius_b;
     }
     public void print()
     {
         System.out.println("圆的面积为"+this.area());
     }
    }

class Triangle extends PlaneGraphics1 implements Graphics
{
    private double bottom ;
    private double height;
    public Triangle(double bottom ,double height)
    {
        this.bottom=bottom;
        this.height=height;
    }
    public double area()
    {
        return bottom*height/2;
    }
    public void print()
    {
        System.out.println("三角形面积为:"+this.area());
    }
    }
public class PlaneGraphics_ex1 {
    public static void main(String[]args)
    {     
        PlaneGraphics1 g=new Rectangle(10.0,20.0);
        g.print();
        g=new Eclipse(10.0,12.0);
        g.print();
        g=new Triangle(10.0,6.0);
        g.print();
    }

}

java接口相关例题的更多相关文章

  1. Java——接口相关知识

    1.接口用interface来声明 //定义一个动物接口 public interface Animal{ public void eat(); public void travel(); } 2.接 ...

  2. java之接口相关知识

    1.接口用interface来声明 //定义一个动物接口 public interface Animal{ public void eat(); public void travel(); } 2.接 ...

  3. java接口调用——webservice就是一个RPC而已

    很多新手一听到接口就蒙逼,不知道接口是什么!其实接口就是RPC,通过远程访问别的程序提供的方法,然后获得该方法执行的接口,而不需要在本地执行该方法.就是本地方法调用的升级版而已,我明天会上一篇如何通过 ...

  4. 规则引擎集成接口(八)Java接口实例

    接口实例 右键点击“对象库” —“添加接口实例”,如下图: 弹出如下窗体: 输入接口的参数信息: 点击接口“求和”,选择选项卡“求和操作”,点击添加图标   ,如下: 弹出如下窗体,勾选方法“coun ...

  5. python面向对象进阶 反射 单例模式 以及python实现类似java接口功能

    本篇将详细介绍Python 类的成员.成员修饰符.类的特殊成员. 类的成员 类的成员可以分为三大类:字段.方法和特性. 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存 ...

  6. Android系统进程间通信Binder机制在应用程序框架层的Java接口源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6642463 在前面几篇文章中,我们详细介绍了A ...

  7. Java:接口继承接口 (多继承机制)

    在看API文档时,突然发现一个接口可以是其他接口的子接口,这说明接口之间会存在继承的关系.查找了相关的资料,做一个总结. 是继承还是实现 首先要搞清楚接口之间的关系使用的关键字是extends还是im ...

  8. java线程相关

    java线程相关 java 线程 1 线程的状态 This is an example of UML protocol state machine diagram showing thread sta ...

  9. php--php调java接口验签

    <?php namespace Fmall_cloud\Model; use Think\Model; class DealJavaModel extends Model { /** * @ti ...

随机推荐

  1. Leetcode 解题 Longest Substring without repeating charcater python

    原题: Given a string, find the length of the longest substring without repeating character For example ...

  2. STM32库函数开发使用总结

    一.外设常具备的几类寄存器 控制寄存器xxx_CR (Control/Configuration Register): 用来配置.控制响应外设的工作方式,如GPIOx_CRL.AFIO_EXTICR1 ...

  3. 黑马程序员-------.net基础知识二

    变量 变量代表着一块内存空间,我们可以通过变量名称想内存存/取数据,有变量就不需要我们记忆复杂的内存地址. 向内存中申请一块内存空间的语法:   数据类型 变量名; 变量类型 变量类型 存储位置 自动 ...

  4. Servlet+Tomcat制作出第一个运行在Tomcat上的Java应用程序

    转载自:http://www.linuxidc.com/Linux/2011-08/41685.htm [日期:2011-08-27] 来源:csdn  作者:Cloudyxuq     1.IDE工 ...

  5. Mac下获取AppStore安装包文件路径

    通过远在大洋彼岸的苹果服务器下载东西,确实有够慢啊!AppStore更甚:甚至都经常提示连不上服务器,而有些软件呢,还必须从AppStore下载安装,所以没办法,谁让上了苹果的贼船呢!公司的网速更是不 ...

  6. VCC,VDD,VEE,VSS,VPP 表示的意义

    转自VCC,VDD,VEE,VSS,VPP 表示的意义 VCC,VDD,VEE,VSS,VPP 表示的意义 版本一: 简单说来,可以这样理解: 一.解释 VCC:C=circuit 表示电路的意思, ...

  7. ECMall的MySQL数据调用的简单方法

    很多ecmall开发者会问,怎么使用Ecmall的mysql类库进行数据调用.从原理上来讲Ecmall的数据调用是以数据模块+模块类库的方式进行mysql数据调用的,所有数据模块都存储在include ...

  8. Android 模拟器上的127.0.0.1 localhost

    调试中通过android simulator模拟器链接localhost或者127.0.0.1,因为我在电脑上面建立了apache,我的代码大概就是URL url = new URL(urlStrin ...

  9. Serv-u FTP服务器

    它可以让我们通过http协议(web端)或者通过其他软件进行连接,从而可以操作服务器上的文件数据.

  10. 使用Spring AOP预处理Controller的参数

    实际编程中,可能会有这样一种情况,前台传过来的参数,我们需要一定的处理才能使用,比如有这样一个Controller @Controller public class MatchOddsControll ...