Java Exception MCQ

Answer all questions carefully. After submission, you will see a detailed result and answer review.

Question 1
What happen in case of multiple catch blocks?
Question 2
System class is defined in .................
Question 3
Which keyword is used to specify the exception thrown by the method?
Question 4
What will be the output of the following piece of code: <pre class="prettyprint"> class Person{ public void talk() {} } public class Test{ public static void main(String args[]){ Person p = null; try{ p.talk(); } catch(NullPointerException e){ System.out.print("There is a NullPointerException. "); } catch(Exception e){ System.out.print("There is an Exception. "); } System.out.print("Everything went fine. "); } } </pre>
Question 5
Exception generated in try block is caught in ........... block.
Question 6
What will be the output? <pre class="prettyprint"> class MyClass{ public String test(){ try{ System.out.print("One"); return ""; } finally{ System.out.print("Two"); } } } public class Test{ public static void main(String args[]){ MyClass m = new MyClass(); m.test(); } } </pre>
Question 7
Determine output of the following program code? <pre class="prettyprint"> public class Test{ public static void main(String args[]){ int i; try{ i = calculate(); System.out.println(i); }catch(Exception e){ System.out.println("Error occured"); } } static int calculate(){ return (7/2); } } </pre>
Question 8
What will be the result after the class Test execution? <pre class="prettyprint"> class A{ public void doA(){ B b = new B(); b.dobB(); System.out.print("doA"); } } class B{ public void dobB(){ C c = new C(); c.doC(); System.out.print("doB"); } } class C{ public void doC(){ if(true) throw new NullPointerException(); System.out.print("doC"); } } public class Test{ public static void main(String args[]){ try{ A a = new A(); a.doA(); }catch(Exception ex){ System.out.print("error"); } } } </pre>
Question 9
Which of the below statement is/are true about Error? <p>A. An Error is a subclass of Throwable.<br />B. An Error is a subclass of Exception.<br />C. Error indicates serious problems that a reasonable application should not try to catch.<br />D. An Error is a subclass of IOException.</p>
Question 10
In which of the following package Exception class exist?