1
/**
* 向上转型
* <p/>
* Created by wang on 15/8/7.
*/
class Cycle {
public void play() {
System.out.println("Cycle play");
}
}
class Unicycle extends Cycle{
@Override
public void play() {
System.out.println("Unicycle play");
}
}
class Bicycle extends Cycle {
@Override
public void play() {
System.out.println("Bicycle play");
}
}
class Tricycle extends Cycle {
@Override
public void play() {
System.out.println("Tricycle play");
}
}
public class UpCast {
public static void ride(Cycle c) {
c.play();
}
public static void main(String[] args) {
Unicycle u = new Unicycle();
Bicycle b = new Bicycle();
Tricycle t = new Tricycle();
ride(u);
ride(b);
ride(t);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-03 04:45:16