类Demo1:
- class Demo1
- {
- public static void func()
- {
- try
- {
- throw new Exception();
- System.out.println("A");//(**)
- }
- catch (Exception e)
- {
- System.out.println("B");
- }
- }
- public static void main(String[] args)
- {
- try
- {
- func();
- }
- catch (Exception e)
- {
- System.out.println("C");
- }
- System.out.println("D");
- }
- }
复制代码
类Demo2:
- class Demo2
- {
- public static void main(String[] args)
- {
- try
- {
- showExec();
- System.out.println("A");
- }
- catch (Exception e)
- {
- System.out.println("B");
- }
- finally
- {
- System.out.println("C");
- }
- System.out.println("D");
- }
- public static void showExec() throws Exception
- {
- throw new Exception();
- }
- }
复制代码
问这两个类是否能编译通过,为什么?
解析:
|
|