try{ File f = new File("a.txt");}catch(Exception e){}catch(IOException io){}Is this code create new file name a.txt ? Compilation Error true None of these false 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. Compilation fails saying NullPointerException has already been caught. "exception" is printed. None of these TRUE ANSWER : ? YOUR ANSWER : ?
Exception generated in try block is caught in ........... block. catch throw finally throws TRUE ANSWER : ? YOUR ANSWER : ?
Which keyword is used to explicitly throw an exception? throw catch throwing try 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 Two One TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following blocks execute compulsorily whether exception is caught or not. finally throws catch throw TRUE ANSWER : ? YOUR ANSWER : ?
Which keyword is used to specify the exception thrown by method? throw throws catch finally TRUE ANSWER : ? YOUR ANSWER : ?
Given the following piece of code:class SalaryCalculationException extends Exception{}class Person{ public void calculateSalary() throws SalaryCalculationException{ //... throw new SalaryCalculationException(); //... }}class Company{ public void paySalaries(){ new Person().calculateSalary(); }}Which of the following statements is correct?1. This code will compile without any problems.2. This code will compile if in method paySalaries() we return a boolean in stead of void.3. This code will compile if we add a try-catch block in paySalaries().4. This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries(). 2 and 4 2 and 3 1 and 4 3 and 4 1 and 2 TRUE ANSWER : ? YOUR ANSWER : ?
What happen in case of multiple catch blocks? The superclass exception cannot caught first. Either super or subclass can be caught first. The superclass exception must be caught first. None of these TRUE ANSWER : ? YOUR ANSWER : ?
In which of the following package Exception class exist? java.file java.io java.net java.util java.lang TRUE ANSWER : ? YOUR ANSWER : ?