A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© xwh1230 中级黑马   /  2014-7-24 20:25  /  941 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

写出程序结果
class Demo
{       
        public static void func()
        {
                try
                {
                        throw  new Exception();                               
                                               
                }
                finally
                {
                        System.out.println("B");
                }
        }
        public static void main(String[] args)
        {
                try
                {
                        func();
                        System.out.println("A");
                }
                catch(Exception e)
                {
                        System.out.println("C");
                }
                System.out.println("D");
        }
}


1 个回复

倒序浏览
输出结果依次是b,c,d,因为执行func方法时,出现异常,执行finallyb,然后catch捕捉异常,执行c,最后执行d
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马