class Computer
{
private int state=3; //电脑状态:1,表正常,2,表蓝屏,3,冒烟
public void run()throws LanPingException,MaoYanException //这里必须声明异常
{
//对state进行判断后,就抛出相应的异常处理。
if(state==2)
throw new LanPingException("电脑蓝屏了!");
if(state==3)
throw new MaoYanException("电脑冒烟了!");
System.out.println("电脑运行中......");
}
public void restart()
{
state=1; //让电脑状态处于正常,再重启。
System.out.println("此时电脑正常,电脑重启!");
}
}
class Teacher
{
private String name;
private Computer computer;