Which loop in Java is guaranteed to execute at least once, even if the condition is initially false?
enhanced for loop
for loop
do-while loop
while loop
What are fields in a Java class?
Constructors used to create objects
Methods that belong to the class
Variables that hold the state of an object
Keywords reserved by the Java language
What is the purpose of the 'switch' statement in Java?
To declare a variable
To check a condition and execute different code blocks based on the result
To execute a block of code repeatedly
To define a method
Which access modifier allows a class's members to be accessed from anywhere?
public
protected
private
default
What is the base case in a recursive function?
The return statement of the function.
The condition that stops the recursion.
The most complex part of the recursion.
The initial call to the function.
What is the difference between a class and an object in Java?
A class is a variable type, while an object is a function.
A class is a blueprint, while an object is a physical entity.
A class defines properties and behavior, while an object is an instance of a class.
There is no difference; they are interchangeable terms.
What is the output of the following code snippet?
int x = 5; if (x > 10) { System.out.println("Greater than 10"); } else { System.out.println("Less than or equal to 10"); }
Less than or equal to 10
x is 5
Greater than 10
Error
Which of the following is a characteristic of unchecked exceptions in Java?
They are not required to be declared in a method's 'throws' clause.
The compiler requires you to handle them explicitly.
They are derived directly from the 'Error' class.
They typically represent recoverable situations.
Which method is used to add an element to the end of an ArrayList?
push()
insert()
append()
add()
What is the default access modifier for a class member in Java if none is specified?
default (package-private)