Exception Handling
16.What will be the output?
class Test {
public static void main(String[] args) {
try {
return;
} finally {
System.out.println("Finally block executed");
}
}
}
-
A. No output
-
B. Finally block executed
-
C. Compilation Error
-
D. Runtime Error
Finally block executed
Finally block executed
17.What will be the output?
class Test {
public static void main(String[] args) {
try {
throw new Exception();
} catch (RuntimeException e) {
System.out.println("RuntimeException caught");
}
}
}
-
A. RuntimeException caught
-
B. Compilation Error
-
C. No output
-
D. Exception in thread "main" java.lang.Exception
Exception in thread "main" java.lang.Exception
Exception in thread "main" java.lang.Exception
18.What will be the output?
class Test {
public static void main(String[] args) {
try {
System.out.println(5 / 0);
} catch (ArithmeticException e) {
throw e;
}
}
}
-
A. ArithmeticException caught
-
B. No output
-
C. Runtime Exception
-
D. Compilation Error
Runtime Exception
Runtime Exception