Which access modifier allows a subclass in a different package to access a member of its superclass?
protected
public
default
private
Which access modifier allows a class's members to be accessed from anywhere?
What is the role of parameters in a Java method?
To control the method's visibility.
To declare variables within the method.
To define the method's return type.
To provide input values to the method.
What is the base case in a recursive function?
The return statement of the function.
The most complex part of the recursion.
The initial call to the function.
The condition that stops the recursion.
Which loop in Java is guaranteed to execute at least once, even if the condition is initially false?
do-while loop
enhanced for loop
for loop
while loop
Which keyword is used to explicitly throw an exception in Java?
throw
finally
try
catch
What does it mean for a method to have a 'void' return type?
The method throws an exception.
The method returns an empty string.
The method doesn't return any value.
The method is not yet implemented.
What is the time complexity of the get() method for an ArrayList?
get()
O(log n)
O(n log n)
O(n)
O(1)
What will the following Java code snippet print to the console?
for (int i = 1; i <= 3; i++) { System.out.print(i + " "); }
1 2 3
123
The code will result in a compilation error.
3 2 1
What is the purpose of the 'break' statement in a Java 'switch' statement?
It prints an error message to the console.
It terminates the entire program.
It skips the current iteration of a loop.
It exits the 'switch' block after a matching case is found.