Exception - finally

package com.rl.exception;

public class Exception7 {

public static void main(String[] args) {

    int i = method();
    System.out.println("i的结果是:" + i);
}

public static int method(){
    int i = 0;
    int a = 10 ;
    int b = 0;
    try {
        i = 2 ;
        a = a/b;
    } catch (Exception e) {
        i =3 ;
        System.out.println(i);
        return i;

    } finally {
        i = 4 ;
        System.out.println("finall补执行了");
        return i ;
    }
}

}

经常遇到问题:
final,finally,finalize区别?
1.final可以修饰类,方法,属性,如果在类上,类不能被继承,如果在方法上不能重写,如果在属性上值不能改
2.finally是和try..catch异常处理模块一同只用 的语句块,它在最后一定会被执行
3.finalize当堆中的对象没有任何引用时这个方法会被调用来做垃圾回收。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值