Person p = new IronMan();
System.out.println("我: 这谁啊?");
System.out.println("他: 我啊!" + p.name +"!");
System.out.println("我: 你干啥呢 ? ");
System.out.print("他:" );
p.business();
System.out.println("救命啊!!!!");
//变身
IronMan im = (IronMan) p;
im.fly();
im.savePeople();
im.business();
}
}
//定义类 person
class Person {
String name = "托尼.斯塔克";
public void business(){
System.out.println("开工厂挣钱");
}
}
//定义子类 IronMan
class IronMan extends Person{
String name = "钢铁侠";
public void business(){
System.out.println("拍照挣钱,5块一张");
}
public void fly(){
System.out.println("飞飞飞~~~~");
}
public void savePeople(){
System.out.println("救人 ");
}