1.  What is the output of this program ?
class exception_handling {
public static void main(String args[]) {
try {
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
sum = (sum / i);
}
catch(ArithmeticException e) {
System.out.print(‘’0’’);
}
System.out.print(sum);
}
}


0.
06
05
Runtime Error


Answer

 Option

Value of variable sum is printed outside of try block, sum is declared only in try block, outside try block it is undefined.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

2.  What is the output of this program?
class exception_handling {
public static void main(String args[]) {
try {
System.out.print(‘’Hello’’ + ‘’ ‘’ + 1 / 0);
}
catch(ArithmeticException e) {
System.out.print(‘’World’’);
}
}
}


Hello
World
HelloWorld
Hello World


Answer

 Option

System.ou.print() function fist converts the whole parameters into string and then prints, before “Hello” goes to output stream 1 / 0 error is encountered which is cached by catch block printing just “World” . Output: $ javac exception_handling.java $ java exception_handling World

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

3.  Which keyword is used to specify the exception thrown by method ?


catch
throws
finally
throw


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

4.  Which of the following blocks execute compulsorily whether exception is caught or not.


finally
catch
throws
throw


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

5.  What happen in case of multiple catch blocks ?


Either super or subclass can be caught first
The superclass exception must be caught first
The superclass exception cannot caught first
None of these


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report