Question 71
Given:
11.classA {
12. public void process()
{ System.out.print(“A,”)} }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print(“B,”)
17. throw new IOException();
18. } }
19. public static void main(String[] args)
{
20. try { new B().process(); }
21. catch (IOException e) { System.out.println(“Exception”)} }
What is the result?
A. Exception
B. A,B,Exception
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 14.
E. A NullPointerException is thrown at runtime.
Answer: D
Question 72
Given:
11.classA
{
12. public void process() { System.out.print(“A “)} }
13. class B extends A {
14. public void process() throws RuntimeException {
15. super.process();
16. if (true) throw new RuntimeException();
17. System.out.print(“B”)
}}
18. public static void main(String[] args) {
19. try { ((A)new B()).process(); }
20. catch (Exception e) { System.out.print(“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.
Answer: B这两道题好像啊,只是IOException与RuntimeException的区别,为什么会这样呢?请路过的神仙哥哥姐姐给小弟好好解释一下好吗?谢谢。。
Given:
11.classA {
12. public void process()
{ System.out.print(“A,”)} }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print(“B,”)
17. throw new IOException();
18. } }
19. public static void main(String[] args)
{
20. try { new B().process(); }
21. catch (IOException e) { System.out.println(“Exception”)} }
What is the result?
A. Exception
B. A,B,Exception
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 14.
E. A NullPointerException is thrown at runtime.
Answer: D
Question 72
Given:
11.classA
{
12. public void process() { System.out.print(“A “)} }
13. class B extends A {
14. public void process() throws RuntimeException {
15. super.process();
16. if (true) throw new RuntimeException();
17. System.out.print(“B”)
}}
18. public static void main(String[] args) {
19. try { ((A)new B()).process(); }
20. catch (Exception e) { System.out.print(“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.
Answer: B这两道题好像啊,只是IOException与RuntimeException的区别,为什么会这样呢?请路过的神仙哥哥姐姐给小弟好好解释一下好吗?谢谢。。
IO...是受检查异常,编译会检查
Answer: D
重写父类方法的时候,不能比原方法更严格的限制
我觉得问题出在这里