public class Main { public static void main(String[] args) {
System.out.println(test());
} public static boolean test() {
boolean b = false;
try { return b = 4 > 3;
} finally {
System.out.println(b);
}
}
} 那位能帮忙解释一下这段程序,我运行的结果是 两个 True; 不胜感激;
System.out.println(test());
} public static boolean test() {
boolean b = false;
try { return b = 4 > 3;
} finally {
System.out.println(b);
}
}
} 那位能帮忙解释一下这段程序,我运行的结果是 两个 True; 不胜感激;
System.out.println(test());
} public static boolean test() {
boolean b = false;
try { return b = 4 > 3;
} finally {
System.out.println(b);
}
}
} 那位能帮忙解释一下这段程序的运行过程,我运行的结果是 两个 True; 不胜感激;
因此:这时的b值是true2)执行: finally {}部分,打印出b值,输出true
3)此时:return 返回b的值,即:true
4)最后在main()中执行:System.out.println(...); 输出true
我也是这么觉得的。你可以在finally中改变输出字符,就知道结论了。
1)
public class Main1 { public static void main(String[] args) {
System.out.println(test());
} public static int test() {
int b = 1;
try { return b ;
} finally {
b++;
}
}
}
则:程序的输出结果是 1 还是 2?2)若程序改为:public class Main1 { public static void main(String[] args) {
System.out.println(test());
} public static int test() {
int b = 1;
try { return b ;
} finally {
b++;
return b ;
}
}
}
则:程序的输出结果是 1 还是 2?