黑马程序员技术交流社区

标题: 用代码证明,在try中写了return,是先执行. [打印本页]

作者: 革命卍    时间: 2016-6-4 23:57
标题: 用代码证明,在try中写了return,是先执行.
用代码证明,在try中写了return,后面又写了finally,是先
作者: 何亚辉    时间: 2016-6-7 15:47
package com.heima.IO;

public class Day1_ClassTest2 {
        public static void main(String[] args) {

                System.out.println(test());

        }

        public static int test() {
                try {

                        System.out.println(10 / 0);
                        return 10;
                } catch (Exception e) {
                        int i = 20;
                        return i;
                } finally {
                        int i = 30;
                }
        }

}

作者: 土菠萝    时间: 2016-6-7 15:53
何亚辉 发表于 2016-6-7 15:47
package com.heima.IO;

public class Day1_ClassTest2 {

额,好像是这样子
作者: Fangjie    时间: 2016-6-7 16:13
测试了下,是try先执行,然后finally,最后是方法的返回值,然后在main函数中打印




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2