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. python 循环while和for in

    #!/uer/bin/env python # _*_ coding: utf-8 _*_ lucknumber = 5 b = 0 while b <3: print('guss count: ...

  2. Python 手册(一)

    Python 手册 Guido van Rossum Fred L. Drake,  Jr., editor PythonLabs Email: python-docs@python.org Rele ...

  3. 在虚拟机的linux中利用VMware Tools实现与windows共享文件

        很多人都知道安装"VMware Tools"可以实现与windows共享,但是其实它的功能远不止此.安装了"VMware Tools"后,虚拟机的网络. ...

  4. Ansj分词双数组Trie树实现与arrays.dic词典格式

    http://www.hankcs.com/nlp/ansj-word-pairs-array-tire-tree-achieved-with-arrays-dic-dictionary-format ...

  5. 系统的了解DJANGO中数据MODULES的相关性引用

    数据库结构如下: from django.db import models class Blog(models.Model): name = models.CharField(max_length=1 ...

  6. OA学习笔记-005-Spring2.5与struts2.1整合

    一.单独测试strust 1.action package cn.itcast.oa.test; import org.springframework.context.annotation.Scope ...

  7. bzoj2426

    稍微列个式子就知道是贪心 ..] of longint; m,b,h0,n,i,p,j,x,ans,s:longint; procedure swap(var a,b:longint); var c: ...

  8. POJ_1182_食物链_[NOI]_(并查集)

    描述  http://poj.org/problem?id=1182 共A,B,C三种动物,A吃B,B吃C,C吃A.给出询问 q : t , x , y , 表示: x 与 y 是同类 ( t==1 ...

  9. Devexpress GridView部分常用操作总结 z

    一:Clone返回新的 DataTable Clone返回新的 DataTable,与当前的 DataTable 具有相同的架构:Copy:返回新的 DataTable,它具有与该 DataTable ...

  10. AudioMixer的脚本控制

    AudioMixer是Unity5新特性之一,能很好的实现立体声效果. 这儿先记录一下脚本控制的方法: 1.添加一个Group,然后点击它 2.右侧面板上出现2个参数:pitch(速度)和volume ...