黑马程序员技术交流社区
标题:
一道关于throw和try/catch的面试题。
[打印本页]
作者:
halohoop
时间:
2015-7-28 17:47
标题:
一道关于throw和try/catch的面试题。
类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();
}
}
复制代码
问这两个类是否能编译通过,为什么?
解析:
作者:
fmi110
时间:
2015-7-28 18:36
本帖最后由 fmi110 于 2015-7-28 18:38 编辑
复习了 原来代码块中包含无法执行到的语句 JVM也会报错
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2