Welcome Guest | Sign in | Register
Exceptions - Discussion Page For Q.2637 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Exceptions > Questions and Answers

Q: Given:
1. class A {
2. public void process() { System.out.print("A,"); }}
3. class B extends A {
4. public void process() throws IOException {
5. super.process();
6. System.out.print("B,");
7. throw new IOException();
8.}
9. public static void main(String[] args) {
10. try { new B().process(); }
11. 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 10. D. Compilation fails because of an error in line 4.
E. A NullPointerException is thrown at runtime.

Answer and Explanation

Answer:Compilation fails because of an error in line 4.

Explanation:
process( ) in super class A is not throwing any exception. When we override in child class it should not throw any exception. If in child class overridden method throws an exception then it fails during compilation time.
So D) is correct.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.