class Teacher
{
private String name;
private Computer cmpt;
Teacher(String name)
{
this.name=name;
cmpt=new Computer();
}
public void prelect()
{
try
{
cmpt.run();
}
catch(LanpingException e)
{
cmpt.reset();
}
catch(MaoyanException e)
{
System.out.println("放假");
}
System.out.println("讲课");
}
}
class LanpingException extends Exception
{
LanpingException(String message)
{
super(message);
}
}
class MaoyanException extends Exception
{
MaoyanException(String message)
{
super(message);
}
}
class Computer
{
private int state=3;
public void run() throws MaoyanException,LanpingException
{
if(state==2)
{
new LanpingException("蓝屏了");
}
if(state==3)
{
new MaoyanException("冒烟了");
}
System.out.println("电脑运行");
}
public void reset()
{
state=1;
System.out.println("电脑重启");
}
}
class Exceptiondemo
{
public static void main(String[] args)
{
Teacher t=new Teacher("老毕");
t.prelect();
}
}
当我把state的值无论换成2或者3,运行的结果都如我上传的图片截图,哪位大神知道原因
|
|