2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1.创建一个只能存放String的泛型ArrayList的语句是哪项?
答案:B
A.ArrayListal = new ArrayList();
B.ArrayListal = new ArrayList();
C.ArrayList al = new ArrayList();
D.ArrayListal = new List();
2."下列代码的执行结果是?
class Example {
private void method1() throws Exception {
throw new RuntimeException();
}
public void method2() {
try {
method1();
} catch (RuntimeException e) {
System.out.println(""Caught Runtime Exception"");
} catch (Exception e) {
System.out.println(""Caught Exception"");
}
}
public static void main(String[] args) throws IOException {
Example a = new Example();
a.method2();
}
}"
答案:
A.代码编译失败
B.输出Caught Runtime Exception
C.输出Caught Exception
D.输出Caught Runtime Exception和Caught Exception
3."以下代码的输出结果是什么?选择所有的正确答案。
class Example {