标签:java
1.多态
package com.yuanzijian02;
public class PolyTest {
public void run(Car car){
car.run();
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
PolyTest test = new PolyTest();
Car car = new BWM();
test.run(car);
//向下类型转换
QQ qq = new QQ();
test.run(qq);
}
}
class Car {
public void run(){
System.out.println("car is runing ");
}
}
class BWM extends Car{
public void run(){
System.out.println("BWM is runing");
}
}
class QQ extends Car{
public void run(){
System.out.println("QQ is running");
}
}标签:java
原文地址:http://hnyuanzijian.blog.51cto.com/8869344/1774110