finally关键字

时间:2021-11-07 22:13:20

final:禁止多态开关~
修饰变量:变量不能被改变
修饰类:类不能被继承
修饰方法:方法不能被重写

finally:用在异常处理的最后一个语句块
无论是否产生异常都要被执行~~~

Java代码 
     public final class FinallyTest {
public static void main(String[] args) {
try {
throw new NullPointerException();
} catch (NullPointerException e) {
System.out.println("程序抛出了异常");
} finally {
System.out.println("执行了finally语句块");
}
}
}