package demo3;
import java.awt.*;
/**
* @Author: 黑木~
* @DATE: 2022/11/16 12:57
*/
interface IShape{
void draw();
}
class Cycle implements IShape{
@Override
public void draw() {
System.out.println("画~●~");
}
}
class Flower implements IShape{
@Override
public void draw() {
System.out.println("画~❀~");
}
}
public class TestDemo2 {
public static void drawMap(IShape shapes) {
shapes.draw();
}
public static void main(String[] args) {
/*传参时向上转型
Cycle cycle = new Cycle();*//*传参时向上转型*//*
Flower flower = new Flower();
drawMap(cycle);
drawMap(flower);*/
/*实例化对象是向上转型*/
IShape shape = new Cycle();
IShape shape1 = new Flower();
drawMap(shape);
drawMap(shape1);
}
}