gpt4 book ai didi

Java 公共(public)类 Plane

转载 作者:行者123 更新时间:2023-11-29 07:42:37 28 4
gpt4 key购买 nike

嗨,有人可以看看这个程序吗?我不明白为什么输出是 _c。书上的回答是“一旦s3()抛出异常给s2(),s2()抛给s1(),s2()的代码就不会再执行了”。为什么不呢?

public class Plane {
static String s = "_";
public static void main(String[] args) {
new Plane().s1();
System.out.println(s);
}
void s1() {
try { s2(); }
catch (Exception e) { s += "c"; }
}
void s2() throws Exception {
s3(); s+= "2";
s3(); s+= "2b";
}
void s3() throws Exception {
throw new Exception();
}

}

最佳答案

第一次从 s2 调用 s3 导致在 s2 中发生任何连接之前抛出异常,因此没有任何s2 中的字符串添加将永远执行。因此,对原始字符串的唯一添加是在 s1 中捕获该异常的地方。

关于Java 公共(public)类 Plane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28771159/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com