package com.lrq;
/**
*
* @author 李瑞琦
*
*/
public class TestPoly3 {
public static void main(String[] args) {
Person person = new Person();
Car car = new Car();
Car c1 = new Audi();
Car c2 = new Auto();
person.driver(car);
}
}
class Person{
public void driver(Car car){
car.run();
}
}
class Car{
public void run(){
System.out.println("Car.run(我是车)");
}
}
class Audi extends Car{
@Override
public void run() {
System.out.println("Audi.run(我是奥迪)");
}
}
class Auto extends Car{
@Override
public void run() {
System.out.println("Auto.run(我是Auto)");
}
}
多态 3 polymorphism
最新推荐文章于 2024-07-30 10:24:54 发布