Which of the following blocks execute compulsorily whether exception is caught or not. throw finally throws catch TRUE ANSWER : ? YOUR ANSWER : ?
Exception generated in try block is caught in ........... block. throw catch throws finally 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(); }} Compilation Error One Two None of these One Two TRUE ANSWER : ? YOUR ANSWER : ?
In which of the following package Exception class exist? java.lang java.file java.io java.net java.util TRUE ANSWER : ? YOUR ANSWER : ?
What is the output of the following program code?public class Test{ public static void main(String args[]){ try{ int i; return; } catch(Exception e){ System.out.print("inCatchBlock"); } finally{ System.out.println("inFinallyBlock"); } }} The program will return without printing anything inCatchBlock inFinallyBlock inCatchBlock inFinallyBlock 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(); }} Compilation succeed but no output printName() None of these Value-A Compilation fails-Exception NullPointerException is not compatible with throws clause in Name-B TRUE ANSWER : ? YOUR ANSWER : ?
try{ File f = new File("a.txt");}catch(Exception e){}catch(IOException io){}Is this code create new file name a.txt ? None of these Compilation Error false true TRUE ANSWER : ? YOUR ANSWER : ?
Which exception is thrown when an array element is accessed beyond the array size? None of these ArrayIndexOutOfBounds ArrayIndexOutOfBoundsException ArrayElementOutOfBounds TRUE ANSWER : ? YOUR ANSWER : ?
What will be the result after the class Test execution?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"); } }} "doAdoBdoC" is printed "error" is printed nothing is printed "doCdoBdoA" is printed "doBdoAerror" is printed TRUE ANSWER : ? YOUR ANSWER : ?
What happen in case of multiple catch blocks? None of these Either super or subclass can be caught first. The superclass exception must be caught first. The superclass exception cannot caught first. TRUE ANSWER : ? YOUR ANSWER : ?