class Demo_SuperMan {
public static void main(String[] args) {
Person p = new SuperMan(); //向上转型
p.谈生意();
System.out.println(p.name);
System.out.println("---------------------------------");
SuperMan w = (SuperMan) p; //向下转型
w.fly();
w.谈生意();
System.out.println(w.name);
}
}
class Person {
String name = "john";
public void 谈生意() {
System.out.println("谈生意");
}
}
class SuperMan extends Person {
String name = "SuperMan";
public void 谈生意() {
System.out.println("谈几个亿的大单子");
}
public void fly() {
System.out.println("飞出去救人");
}
}
|
|