zoukankan      html  css  js  c++  java
  • Java-- 类型信息

      不想写文字啊!

     1 package typeinfo;
     2 
     3 import java.util.*;
     4 
     5 abstract class Shape{
     6     void draw(){ System.out.println(this + ".draw()");}
     7     abstract public String toString();
     8 }
     9 
    10 class Circle extends Shape{
    11     public String toString(){
    12         return "Circle";
    13     }
    14 }
    15 
    16 class Square extends Shape{
    17     public String toString(){
    18         return "Square";
    19     }
    20 }
    21 
    22 class Triangle extends Shape{
    23     public String toString(){
    24         return "Triangle";
    25     }
    26 }
    27 
    28 
    29 public class Shapes {
    30     public static void main(String [] args){
    31         List<Shape>  shapelist = Arrays.asList(
    32                 new Circle(), new Square(),new Triangle());
    33         for(Shape shape:shapelist)
    34             shape.draw();
    35     }
    36 }

    结果:

    1 Circle.draw()
    2 Square.draw()
    3 Triangle.draw()
  • 相关阅读:
    Delete Them
    Toda 2
    JQuery案例:购物车加减
    JQuery案例:折叠菜单
    JQuery案例:暖心小广告
    JQuery案例:左右选
    JQuery动画
    JQuery切换事件
    JQuery文档操作
    JQuery选择器
  • 原文地址:https://www.cnblogs.com/fxyfirst/p/3812730.html
Copyright © 2011-2022 走看看