test8.5
来源:互联网 发布:淘宝店铺没流量没访客 编辑:程序博客网 时间:2024/06/06 08:35
在Cycle修改了构造函数,并增加一个wheels()函数,然后Unicycle Bicycle Triangle cycle的构造函数全部随之修改,最后根据前面的修改变化ride()就可以出来题目要求的效果
class Cycle
{private int n;Cycle(int i){n=i;System.out.println("Cycle constructor");}
public int wheels(){return n;}}
class Unicycle extends Cycle{
Unicycle(int i){super(i);System.out.println("Unicycle constructor");}
}
class Bicycle extends Cycle{
Bicycle(int i){super(i);System.out.println("Bicycle constructor");}
}
class Tricycle extends Cycle{
Tricycle(int i){super(i);System.out.println("Tricycle constructor");}
}
public class Test5 {
public void ride(Cycle c){System.out.println("Wheels numbers= "+c.wheels());}
public static void main(String[] args) {
Test5 t=new Test5();
t.ride(new Unicycle(1));
//t.ride(new Bicycle(2));
//t.ride(new Tricycle(3));
}
}
0 0
- test8.5
- test8
- test8
- test8.1
- test8.2
- test8.3
- test8.4
- test8.6
- test8.9
- test8.10
- test8.11
- test8.12
- test8.13
- test8.14
- test8.15
- test8.16
- test8.17
- 打印图形Test8
- Servlet分页技术
- Listview中一些小的注意问题
- c#读取指定路径的配置文件
- OCiOS开发:地图与定位
- replaced element ,input,select
- test8.5
- 阿里巴巴中间件性能挑战赛(RPC篇 复杂版)
- 游戏中实现快速点击功能(即双击)
- 链表中倒数第k个节点
- strcpy和memcpy
- 延迟脚本
- 如何在action中访问servlet API
- jaxb注解
- 重载问题