Which exception is thrown when a method argument is null but shouldn't be?
Answer: B
NullPointerException is thrown when attempting to use an object reference that hasn't been instantiated. Java doesn't have NullArgumentException.
Q.442Medium
What happens if you use 'return' statement inside a finally block?
Answer: B
A return statement in finally will override and suppress any return value or exception from try/catch blocks. This is considered a bad practice.
Q.443Hard
Which of the following is NOT a characteristic of Exception class in Java?
Answer: B
Exception class has both checked subclasses (like IOException) and unchecked subclasses (like RuntimeException). Not all exceptions extending Exception are checked.
Q.444Medium
What will be printed?
public class Test {
public static void main(String[] args) {
try {
System.out.println("In try");
return;
} catch (Exception e) {
System.out.println("In catch");
} finally {
System.out.println("In finally");
}
}
}
Answer: B
Try block executes printing 'In try', then return is encountered. Finally block still executes printing 'In finally' before method returns. Catch is skipped as no exception occurs.
Q.445Hard
Which of the following cannot throw a checked exception without being declared in throws clause?
Answer: D
Checked exceptions in constructors, instance initializers, and static initializers must be handled with try-catch or declared in throws (constructors only). This is enforced by Java compiler.
Advertisement
Q.446Medium
What is the output of exception chaining in Java?
Answer: B
Exception chaining wraps a caught exception within another exception using initCause() or constructor, preserving the original exception for debugging and stack trace analysis.
Q.447Medium
Which method is used to get the exception that caused the current exception in Java?
Answer: B
The getCause() method returns the Throwable that caused the current exception, enabling exception chaining analysis and debugging.
Q.448Easy
What happens when an unchecked exception is not caught?
Answer: B
Unchecked exceptions (RuntimeException subclasses) don't require explicit handling. If not caught, they propagate up the call stack, eventually terminating the thread if not caught anywhere.
Q.449Easy
Which exception is thrown when attempting to access an index outside the bounds of an array?
Answer: B
ArrayIndexOutOfBoundsException is thrown when attempting to access array elements with invalid indices. It's an unchecked exception extending RuntimeException.
Q.450Hard
What is the execution order in try-catch-finally for nested exception handling?
Answer: B
Nested exception handling follows inner-to-outer order. Inner try-catch-finally completes fully, then control passes to outer blocks. Finally blocks execute in their respective scope order.
Q.451Easy
Consider a method signature: public void readFile() throws IOException. Which statement is correct?
Answer: B
throws declaration indicates the method may throw IOException. The caller is responsible for handling it with try-catch or declaring throws. The method doesn't always throw it.
Q.452Hard
What is suppressed exception in Java (introduced in Java 7)?
Answer: B
In try-with-resources, if an exception occurs in try and another in resource close(), the second is added as suppressed exception to the first using addSuppressed(), preserving all exception information.
Q.453Easy
Which of the following statements about try-catch-finally blocks is correct?
Answer: A
The finally block always executes regardless of whether a return, break, continue, or exception occurs in try or catch blocks, unless System.exit() is called.
Q.454Easy
What is the output of the following code?
public class ExceptionTest {
public static void main(String[] args) {
try {
int x = 010;
} catch (ArithmeticException e) {
System.out.println("Caught");
} finally {
System.out.println("Finally");
}
}
}
Answer: A
ArithmeticException is caught by the catch block printing 'Caught', then finally block executes printing 'Finally'.
Q.455Easy
What will be the output?
public class Test {
public static void main(String[] args) {
try {
throw new Exception("Test");
} catch (Exception e) {
System.out.println("1");
} catch (Exception e) {
System.out.println("2");
}
}
}
Answer: C
Multiple catch blocks with the same exception type cause compilation error. Java doesn't allow duplicate catch blocks for identical exception types.
Q.456Medium
Which exception is thrown when a thread tries to acquire a monitor that is already locked?
Answer: B
IllegalMonitorStateException is thrown when an invalid monitor state operation occurs, such as calling notify() on an object not owned by the current thread.
Q.457Medium
Consider the following code. What will be printed?
public class FinallyTest {
public static int getValue() {
try {
return 10;
} finally {
System.out.println("Finally");
}
}
public static void main(String[] args) {
System.out.println(getValue());
}
}
Answer: A
finally block executes before the return statement completes. System.out.println in finally executes first, then the return value 10 is printed.
Q.458Medium
Which of the following statements is true regarding exception constructors?
Answer: B
Exception class provides multiple constructors including one with String message and another with String message and Throwable cause for exception chaining.
Q.459Medium
What is the output of multi-level exception chaining?
public class ChainTest {
public static void main(String[] args) {
try {
try {
throw new IOException("IO Error");
} catch (IOException e) {
throw new RuntimeException("Runtime Error", e);
}
} catch (RuntimeException e) {
System.out.println(e.getCause().getClass().getSimpleName());
}
}
}
Answer: B
getCause() returns the IOException that was wrapped. getClass().getSimpleName() returns 'IOException'.
Q.460Medium
Which of the following best describes a custom exception in Java?
Answer: B
Custom exceptions should extend Exception (for checked) or RuntimeException (for unchecked) depending on usage requirements.