zoukankan      html  css  js  c++  java
  • shapes

    接口 shape

    package shape;

    public abstract interface shape {

    public abstract void Draw();
    public abstract void getString();
    public static void main(String[] args) {

    }

    }

     实体类矩形

    package shape;

    public class Rect implements shape{
    private int length = 0;
    private int wideth = 0;
    public Rect(int length,int wideth){
    this.length = length;
    this.wideth = wideth;
    }
    public void Draw(){
    System.out.println("Draw Rect");
    }

    public void getString() {
    System.out.println("Rect [length=" + length + ", wideth=" + wideth + "]");
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

    }

    实体类 圆

    package shape;

    public class Circle implements shape{
    private int Radius = 0;
    public Circle(int Radius){
    this.Radius = Radius;
    }
    public void Draw(){
    System.out.println("Draw Circle");
    }

    public void getString() {
    System.out.println("Circle [Radius=" + Radius + "]");
    }
    public static void main(String[] args) {

    }

    }

    多态   操作

    package shape;

    public class Board {

    public shape[] S = { new Circle(1), new Circle(2)
    , new Circle(3), new Rect(1,2)
    , new Rect(2,3), new Rect(3,4) };

    public void Refresh(shape s) {
    s.Draw();
    s.getString();
    }

    public static void main(String[] args) {
    Board B = new Board();
    for (int i = 0; i < 6; i++) {
    B.Refresh(B.S[i]);
    }
    }

    }

  • 相关阅读:
    Qt 学习之路 2(39):遍历容器
    Qt 学习之路 2(38):存储容器
    JS 格式化日期
    springboot 核心注解
    Java 生成随机数 Random、SecurityRandom、ThreadLocalRandom、Math.random()
    验证码 easy_captcha
    读过的书籍
    typora 常用快捷键
    kafka 遇到的问题
    老男孩Linux 运维
  • 原文地址:https://www.cnblogs.com/the-wang/p/6538368.html
Copyright © 2011-2022 走看看