Govt. Exams
Entrance Exams
Advertisement
Topics in Java Programming
What is the output of the following code?
int x = 10;
try {
x = x / 0;
} catch(ArithmeticException e) {
x = x + 5;
} finally {
x = x * 2;
}
System.out.println(x);
int x = 10;
try {
x = x / 0;
} catch(ArithmeticException e) {
x = x + 5;
} finally {
x = x * 2;
}
System.out.println(x);
Correct Answer:
B. 30
EXPLANATION
ArithmeticException is caught, x becomes 10+5=15. Finally block executes, x becomes 15*2=30. Finally block always executes regardless of exception.