- class Computer //创建一个类包括电脑的功能
- {
- private int state = 3;//键入不同的值可能导致电脑出现异常
- public void run() throws LanPingException,MaoYanException
- {
- if (state == 2)
- throw new LanPingException("蓝屏了");
- if (state == 3)
- throw new MaoYanException("冒烟了");
- System.out.println("电脑运行");
- }
- public void reset()//重启功能
- {
- state = 1;
- System.out.println("电脑重启");
- }
- }
- class Teacher//创建一个类包括:老师用电脑讲课及安排小练习
- {
- private String name;//定义老师名字
- private Computer cmpt;//定义所使用电脑
- Teacher(String name)//自定义一个构造方法
- {
- this.name = name;
- cmpt = new Computer();
- }
复制代码 倒数第一行 cmpt = new Computer();//
而不是 Computer cmpt = new Computer();
|
|