public class Test{ public static void main(String args[]){ try{ int a = Integer.parseInt("four"); } }}Which exception could be handled by the catch block for above? None of these IllegalStateException ClassCastException ArrayIndexOutOfBoundsException NumberFormatException TRUE ANSWER : ? YOUR ANSWER : ?
Predict the output:public class Test{ public static void main(String args[]){ try{ String arr[] = new String[10]; arr = null; arr[0] = "one"; System.out.print(arr[0]); }catch(Exception ex){ System.out.print("exception"); }catch(NullPointerException nex){ System.out.print("null pointer exception"); } }} "one" is printed. "null pointer exception" is printed. "exception" is printed. None of these Compilation fails saying NullPointerException has already been caught. TRUE ANSWER : ? YOUR ANSWER : ?
What will be the result of executing the following code?public class Test{ public void divide(int a, int b){ try{ int c = a / b; }catch(Exception e){ System.out.print("Exception "); }finally{ System.out.println("Finally"); } public static void main(String args[]){ Test t = new Test(); t.divide(0,3); }} Prints out: Exception Finally None of these Prints out: Finally Compile with error Prints out: Exception TRUE ANSWER : ? YOUR ANSWER : ?
What will be the output?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(); }} One Two One None of these Compilation Error Two TRUE ANSWER : ? YOUR ANSWER : ?
Which exception is thrown when an array element is accessed beyond the array size? ArrayElementOutOfBounds ArrayIndexOutOfBoundsException None of these ArrayIndexOutOfBounds TRUE ANSWER : ? YOUR ANSWER : ?
What is the output for the below code ?import java.io.FileNotFoundException;class A{ public void printName() throws FileNotFoundException{ System.out.println("Value-A"); }}class B extends A{ public void printName() throws NullPointerException{ System.out.println("Name-B"); }}public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); }} printName() None of these Value-A Name-B Compilation succeed but no output Compilation fails-Exception NullPointerException is not compatible with throws clause in TRUE ANSWER : ? YOUR ANSWER : ?
What will be the result if NullPointerException occurs at line 2?1. try{2. //some code goes here3. }4. catch(NullPointerException ne){5. System.out.print("1 ");6. }7. catch(RuntimeException re){8. System.out.print("2 ");9. }10. finally{11. System.out.print("3");12. } 1 3 1 1 2 3 3 2 3 TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following blocks execute compulsorily whether exception is caught or not. throw finally throws catch TRUE ANSWER : ? YOUR ANSWER : ?
What will be the output of the following piece of code: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. "); }} This code will not compile, because in Java there are no pointers. There is a NullPointerException. There is a NullPointerException. Everything went fine. There is a NullPointerException. There is an Exception. TRUE ANSWER : ? YOUR ANSWER : ?
Which of the below statement is/are true about Error?A. An Error is a subclass of Throwable.B. An Error is a subclass of Exception.C. Error indicates serious problems that a reasonable application should not try to catch.D. An Error is a subclass of IOException. A and C B and D B and C A and B A and D TRUE ANSWER : ? YOUR ANSWER : ?