多态

public class Shape {
public void draw(){

}

}
class Cycle extends Shape{
@Override
public void draw(){
System.out.println(“o”);
}
}
class Rect extends Shape{
@Override
public void draw(){
System.out.println(“口”);
}
}
class Flower extends Shape{
@Override
public void draw(){
System.out.println(“❀”);
}
}
class Test1{
public static void main(String[] args) {
Shape shape=new Cycle();
shape.draw();
shape=new Flower();
shape.draw();
shape=new Rect();
shape.draw();
}
}
多态
一个引用,能表现出多种不同形态.

上一篇:python设计模式


下一篇:装饰器模式(Java)