PRACTICE • LEARN • GROW
Module 9: Exception Handling - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 9: Exception Handling - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the root class of the entire Java exception and error hierarchy?
A.
java.lang.Exception
B.
java.lang.Throwable
C.
java.lang.Error
D.
java.lang.RuntimeException
Explanation & Key
Correct Answer:
2
Which of the following is an UNCHECKED (runtime) exception in Java?
A.
java.io.IOException
B.
java.sql.SQLException
C.
java.lang.NullPointerException
D.
java.lang.ClassNotFoundException
Explanation & Key
Correct Answer:
3
What will the following method return?
public static int test() {
try {
return 10;
} finally {
return 20;
}
}
A.
10
B.
20
C.
30
D.
Compile-time error: duplicate return statements
Explanation & Key
Correct Answer:
4
What is the difference between the
throw and throws keywords in Java?
A.
throw declares exceptions in method signatures; throws instantiates and fires an exception
B.
throw is used inside method bodies to explicitly trigger an exception instance; throws is used in method signatures to declare exceptions that may propagate out
C.
They are interchangeable synonyms
D.
throw is for checked exceptions; throws is for unchecked exceptions
Explanation & Key
Correct Answer:
5
What occurs when compiling the following try-catch structure?
try {
int x = 10 / 0;
} catch (Exception e) {
System.out.println("Exception");
} catch (ArithmeticException ae) {
System.out.println("Arithmetic");
}
A.
Compiles and prints 'Arithmetic'
B.
Compile-time error: unreachable catch block for ArithmeticException (subclass caught after superclass)
C.
Compiles and prints 'Exception'
D.
Throws runtime error
Explanation & Key
Correct Answer:
6
What is the syntax introduced in Java 7 to catch multiple unrelated exceptions in a single catch block?
A.
catch (IOException && SQLException e)
B.
catch (IOException | SQLException e)
C.
catch (IOException, SQLException e)
D.
catch (IOException or SQLException e)
Explanation & Key
Correct Answer:
7
To create a custom CHECKED exception, which class should your custom exception class extend?
A.
java.lang.RuntimeException
B.
java.lang.Exception (or any checked subclass, excluding RuntimeException)
C.
java.lang.Error
D.
java.lang.Throwable directly
Explanation & Key
Correct Answer:
8
What will be the output of the following code where a primitive variable is modified in finally without an explicit return?
public class Test {
static int compute() {
int x = 10;
try {
return x;
} finally {
x = 20;
}
}
public static void main(String[] args) {
System.out.println(compute());
}
}
A.
20
B.
10
C.
0
D.
Compile-time error
Explanation & Key
Correct Answer:
9
What is printed by the following code when System.exit(0) is called?
try {
System.out.print("Try ");
System.exit(0);
} finally {
System.out.print("Finally ");
}
A.
Try Finally
B.
Try
C.
Finally
D.
Compile-time error
Explanation & Key
Correct Answer:
10
What will be printed by the following exception propagation across call stacks?
class PropagateTest {
static void m3() { throw new RuntimeException("Error"); }
static void m2() { m3(); }
static void m1() {
try { m2(); }
catch (Exception e) { System.out.print("Handled "); }
}
public static void main(String[] args) {
m1();
System.out.print("Done");
}
}
A.
Handled Done
B.
Error
C.
Done
D.
Uncaught RuntimeException
Explanation & Key
Correct Answer:
11
What is the key compile-time characteristic of an Unchecked Exception in Java?
A.
The compiler forces every calling method to add a throws clause
B.
The compiler does NOT enforce handling via try-catch or declaration via throws clause; they represent programmatic logic errors
C.
They can only be caught once per program
D.
They can only be thrown by native C code
Explanation & Key
Correct Answer:
12
Why is catching
java.lang.Throwable or java.lang.Error (e.g. catch (Throwable t)) considered dangerous in production applications?
A.
Because Throwable cannot be instantiated
B.
Because it intercepts fatal JVM failures (like OutOfMemoryError and StackOverflowError) from which the program cannot safely recover, risking state corruption and zombie threads
C.
Because it disables the garbage collector permanently
D.
Because it causes an immediate compilation warning in Java 17
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong