11.  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);
System.out.print(i);
}
}
catch(ArithmeticException e) {
System.out.print(‘’0’’);
}
}
}


-1
0.
-10
-101


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

12.  What is the output of this program ?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print(‘’A’’);
}
catch(ArithmeticException e) {
System.out.print(‘’B’’);
}
finally {
System.out.print(‘’C’’);
}
}
}


A
B
AC
BC


Answer

 Option

finally keyword is used to execute the code before try and catch block end.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

13.  What is the output of this program ?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print(‘’A’’);
}
catch(ArithmeticException e) {
System.out.print(‘’B’’);
}
}
}


A
B
Compilation Error
Runtime Error


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

14.  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

15.  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