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. (转载)StringGrid常用属性和常用操作

    Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...

  2. 开源CMS赏析

    国内CMS产品有很多,开源的产品也不少,大概的可分为以下几类: .NET开源产品:We7CMS: PHP开源产品:Dede CMS.PHP CMS和帝国CMS: ASP开源产品:动易SiteFacto ...

  3. 在ubuntu中获得root权限

    在终端中输入:(1)sudo passwd rootEnter new UNIX password: (在这输入你的密码)Retype new UNIX password: (确定你输入的密码)pas ...

  4. swift 语法 - 以及学习资料

    附上一些swift的一下学习资料: 1.Swift语法介绍官方英文版:The Swift Programming Language 2.Swift与Objective-C相互调用Using Swift ...

  5. iOS面试题16719-b

    1. 反转二叉树,不用递归 /*** Definition for a binary tree node.* public class TreeNode {*     int val;*     Tr ...

  6. 织梦中limit的用法详解(调用指定id下的指定文章)

    limit的用法大致可以理解为:调用指定id下的指定文章. 下面为代码片段,需要的朋友自行拿去: {dede:arclist typeid='6' row='1' limit='0,1'} <l ...

  7. 一周一话题之四(JavaScript、Dom、jQuery全面复习总结<js篇>)

    -->目录导航 一. JavaScript 1. js介绍 2. js语法 3. js进阶 4. js高级 5. 事例代码下载 一. JavaScript 做BS系统,JavaScript的使用 ...

  8. 《转》SQL Server 2008 数据维护实务

    SQL Server 2008 数据维护实务 http://blog.csdn.net/os005/article/details/7739553 http://www.cnblogs.com/xun ...

  9. Gson把json串转换成java实体对象

    Gson把json串转换成java实体对象的方法如下: 1.首先导入Gson的jar包,网上可以下载. java实体对象如下: public class Model { private double ...

  10. 在TMemo上画一条线

    var C:TControlCanvas; begin C := TControlCanvas.Create; C.Pen.Color := clRed; C.Pen.Width := ; C.Con ...