What is the primary purpose of exception handling in Java?
To provide a mechanism for handling unexpected events during program execution.
To completely prevent runtime errors from occurring.
To enforce strict coding standards and prevent compilation errors.
To improve the performance of Java applications.
Which access modifier allows a class's members to be accessed from anywhere?
default
public
private
protected
Which of the following is NOT a valid way to declare an array in Java?
int[] arr;
int arr[] = new int[5];
int []arr;
int arr[];
What will be the value of 'x' after executing the following Java code snippet?
int x = 5; x = x++ + ++x;
The code will result in a compilation error.
11
12
10
Which access modifier allows a subclass in a different package to access a member of its superclass?
Which keyword is used to explicitly throw an exception in Java?
finally
catch
throw
try
What is the base class for all checked exceptions in Java?
Exception
RuntimeException
Throwable
Error
What is the time complexity of the get() method for an ArrayList?
get()
O(1)
O(n log n)
O(n)
O(log n)
What is the purpose of the 'switch' statement in Java?
To declare a variable
To define a method
To check a condition and execute different code blocks based on the result
To execute a block of code repeatedly
What will happen if you try to access an element at an invalid index in an ArrayList?
It will return null.
It will throw a NullPointerException.
The program will crash.
It will throw an ArrayIndexOutOfBoundsException.