JAVA语言基础笔试题-2
翁舟洋 2012-6-8
Question 1
Given:
{
12. public void process() { (“A “)} }
13. class B extends A {
14. public void process() throws RuntimeException {
15. ();
16. if (true) throw new RuntimeException();
17. (“B”)
}}
18. public static void main(String[] args) {
19. try { ((A)new B()).process(); }
20. catch (Exception e) { (“Exception “)}
21. }
What is the result?
A. Exception
B. A Exception
C. A Exception B
D. A B Exception
E. Compilation fails because of an error in line 14.
F. Compilation fails because of an error in line 19.
答案:B
考点:异常的抛出
说明:任何一个方法,将默认在其签名上写上 throws RuntimeException,此处不认为子类重写方法抛出了比父类对应方法更多的异常。
Question 2
Given:
11. static classA
{
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { (“B”)}
16. }
17. public static void main(String[] args) {
a=new B();
19. ();
20.}
What is the result?
A. B
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
F. Compilation fails because of an error in line 19.
答案:A
考点:继承,重写,异常的抛出,
说明:父类A变量指向子类B的对象,调用B中的process()方法
Question 3
Given:
11. static classA {
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { (“B”);
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }
What is the result?
A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
答案:
考点:
说明:
Question 4
Given:
84. try {
85. ResourceConnection con = ();
86. R
JAVA基础面试题 来自淘豆网m.daumloan.com转载请标明出处.