Which of the following is a compile-time error in Java?
A
NullPointerException B
Syntax error C
ArrayIndexOutOfBoundsException D
ClassCastException
Analysis & Theory
A syntax error is detected by the compiler before the program runs.
What type of error is `NullPointerException`?
A
Checked Exception B
Compile-time Error C
Runtime Exception D
Syntax Error
Analysis & Theory
`NullPointerException` is a type of `RuntimeException` thrown during execution.
Which class is the superclass of all errors and exceptions in Java?
A
Object B
Throwable C
Exception D
RuntimeException
Analysis & Theory
`Throwable` is the root class for all errors and exceptions in Java.
Which is a checked exception in Java?
A
IOException B
ArithmeticException C
NullPointerException D
ArrayIndexOutOfBoundsException
Analysis & Theory
`IOException` is a checked exception that must be handled or declared.
Which error indicates that the Java Virtual Machine is out of memory?
A
OutOfMemoryError B
MemoryException C
StackOverflowError D
RuntimeException
Analysis & Theory
`OutOfMemoryError` is thrown when the JVM can't allocate memory.
Which keyword is used to handle exceptions in Java?
A
catch B
try C
handle D
throw
Analysis & Theory
`catch` is used to handle exceptions thrown in the `try` block.
What happens when a checked exception is not handled?
A
Program crashes at runtime B
Compiler shows error C
Program runs normally D
It gets ignored
Analysis & Theory
Checked exceptions must be handled or declared; otherwise, compile-time error occurs.
Which keyword is used to throw an exception manually?
A
throws B
try C
catch D
throw
Analysis & Theory
`throw` is used to manually throw an exception.
What is the purpose of the `finally` block in exception handling?
A
To catch exceptions B
To declare exceptions C
To always execute cleanup code D
To rethrow the exception
Analysis & Theory
`finally` is always executed regardless of exception occurrence, often used for cleanup.
Which of these is **not** an exception type in Java?
A
FileNotFoundException B
NumberFormatException C
StackOverflowError D
IllegalFormat
Analysis & Theory
`IllegalFormat` is not a valid exception type in Java. The correct class is `IllegalFormatException`.