package com.itheima;
/*
* 6、 用代码证明,在try中写了return,后面又写了finally,是先执行return还是先执行fianlly?
*
* 代码运行结果为:
* finally
* 分析:
* 如果先执行return,那么输出为try
* 如果先执行finally,那么输出为finally
*
* 可以证明先执行finally,后执行return
* */
public class Test6
{
public static void main(String[] args)
{
System.out.print(prove());
}
public static StringBuffer prove()
{
StringBuffer sb=new StringBuffer();
try
{
sb.append("try");
return sb;
}
finally
{
sb.replace(0,7,"finally");
}
}
}
|
|