Java面试题:异常、静态变量
1 public class T2 { 2 public static String output = ""; 3 4 public static void f(int i) { 5 try { 6 if (i == 1) { 7 throw new Exception(); 8 } 9 output += "1"; 10 return; 11 } catch (Exception e) { 12 output += "2"; 13 } finally { 14 output += 3; 15 } 16 output += "4"; 17 } 18 }
public class T1 {
public static void main(String[] args) {
T2.f(1);
System.out.println(T2.output); //输出结果:234
//若T2.f(不等1的数)则输出结果为13
}
}