1. 方法的重写, 先看一段代码:
class MyThread extends Thread {
public void run() {
System.out.println("===");
try{
sleep(1000);
}catch(InterruptedException e){
}
}
}
思考一个问题: 直接在run() 方法throws InterruptedException,是否可行?
不可以的!因为 这里 run() 是重写 父类的run(), 父类的方法没有抛出此异常,子类也不能抛出。
即: 重写的方法不能抛出与父类的方法不同的异常!