What is the primary purpose of a method in Java?
To store data
To perform a specific task
To define a class
To control program flow
What is the base class for all checked exceptions in Java?
Exception
RuntimeException
Error
Throwable
What is essential to prevent infinite recursion in a Java method?
A loop within the recursive method
Using a different method name for each recursive call
A conditional statement that terminates the recursion
A return statement in all code paths
Which keyword is used to define a method in Java?
void
function
define
method
Which of the following is NOT a valid way to declare an array in Java?
int arr[];
int[] arr;
int []arr;
int arr[] = new int[5];
Which of the following is NOT a valid access modifier in Java?
protected
public
private
static
Which data type is used to store whole numbers in Java?
String
int
boolean
double
Can a class have multiple constructors?
Constructors are optional, so a class may or may not have any.
Yes, but they must have the same parameter list.
Yes, as long as they have different parameter lists.
No, a class can only have one constructor.
Which loop in Java is guaranteed to execute at least once, even if the condition is initially false?
do-while loop
for loop
while loop
enhanced for loop
What is the difference between a class and an object in Java?
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.
A class is a variable type, while an object is a function.