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]);
    }
    }

    }

  • 相关阅读:
    Codeforces 231E
    Practice 15.07.07 计算几何
    Codeforces 552E
    Topcoder SRM 661 (Div.1) 250 MissingLCM
    HDU 4971
    Codeforces Round #306 (Div. 2)
    URAL 1988
    URAL 2032
    ServiceStack.Ormlit 事务
    ServiceStack.Ormlit 使用Insert的时候自增列不会被赋值
  • 原文地址:https://www.cnblogs.com/the-wang/p/6538368.html
Copyright © 2011-2022 走看看