2024年3月11日发(作者:)
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?
public class Example {
public static void main(String[] args) {
double d = -11.1;
double d1 = method(d);
n(d1);
}
}"
答案: A
()
()
()
()
2."现有如下代码:
public class Example {
public static void main(String[] args) {
try {
n(""before"");
doRisyThing();
n(""after"");
} catch (Exception e) {
n(""catch"");
}
n(""done"");
}
public static void doRisyThing() throws Exception{
//this code returns unless it throws an Exception
}
}
该代码可能的执行结果有哪些?"
答案:
catch
after done
catch done
after catch
3."下列代码的执行结果是?
class Example {
private void method1() throws Exception {
throw new RuntimeException();
}
public void method2() {
try {
method1();
} catch (RuntimeException e) {
n(""Caught Runtime Exception"");
} catch (Exception e) {
n(""Caught Exception"");
}
}
public static void main(String[] args) throws IOException {
Example a = new Example();
2();
}
}"
答案:
A.代码编译失败
B.输出Caught Runtime Exception
C.输出Caught Exception
D.输出Caught Runtime Exception和Caught Exception
4."以下代码的输出结果是什么?选择所有的正确答案。
class Example {
public static void main(String[] args) throws IOException {
for (int i = 0; i < 10; i++) {
try {
try {
if (i % 3 == 0)
throw new Exception(""E0"");
n(i);break;
} catch (Exception inner) {
i *= 2;
if (i % 3 == 0)
throw new Exception(""E1"");
} finally {
发布者:admin,转转请注明出处:http://www.yc00.com/news/1710119269a1703761.html
评论列表(0条)