test8.17
来源:互联网 发布:哪里买古典音乐cd知乎 编辑:程序博客网 时间:2024/05/17 03:56
因为Tricycle没有balance()函数,向下转型后Tricycle对象调用balance()会报错
class Cycle
{Cycle(){System.out.println("Cycle constructor");}}class Unicycle extends Cycle{
Unicycle(){System.out.println("Unicycle constructor");}
public void balance(){System.out.println("Unicycle.balance()");}
}
class Bicycle extends Cycle{
Bicycle(){System.out.println("Bicycle constructor");}
public void balance(){System.out.println("Bicycle.balance()");}
}
class Tricycle extends Cycle{
Tricycle(){System.out.println("Tricycle constructor");}
}
public class Test17 {
public static void main(String[] args) {
Cycle[] cycle={new Unicycle(),new Bicycle(),new Tricycle()};
for(Cycle c:cycle)
c.balance();
((Unicycle)cycle[0]).balance();
((Bicycle)cycle[0]).balance();
((Tricycle)cycle[0]).balance();
}
}
0 0
- test8.17
- test8
- test8
- test8.1
- test8.2
- test8.3
- test8.4
- test8.5
- test8.6
- test8.9
- test8.10
- test8.11
- test8.12
- test8.13
- test8.14
- test8.15
- test8.16
- 打印图形Test8
- RadioButton与ChecxBox
- 连接数据库
- 【转】jdbc事务处理
- 备忘录模式
- 构造函数与析构函数的顺序及动态内存的申请
- test8.17
- 使用 native2ascii.exe 将java utf-8编码批量转换为 ANSI.
- 实现秒杀的几个想法(续)
- C++基类,派生类,同名覆盖原则
- shell 之进行数学运算 let expr bc 中括号
- 用两个队列实现栈
- iOS swift-1
- hdu 5461 Largest Point(水)
- HTML