What is the difference between a class and an object in Java?
There is no difference; they are interchangeable terms.
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.
A class is a variable type, while an object is a function.
What is the process of calling a method in Java?
Creating an object of the class
Declaring the method's return type
Using the method's name followed by parentheses
Defining the method body
Which method is used to add an element to the end of an ArrayList?
insert()
add()
push()
append()
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.
12
10
11
Can a class have multiple constructors?
Constructors are optional, so a class may or may not have any.
Yes, as long as they have different parameter lists.
No, a class can only have one constructor.
Yes, but they must have the same parameter list.
Which keyword is used to explicitly throw an exception in Java?
throw
try
catch
finally
What is essential to prevent infinite recursion in a Java method?
A conditional statement that terminates the recursion
A loop within the recursive method
A return statement in all code paths
Using a different method name for each recursive call
What is the primary difference between an array and an ArrayList in Java?
Arrays can store objects of different classes, while ArrayLists can only store objects of the same class.
Arrays are fixed in size, while ArrayLists are dynamically sized.
Arrays can store primitive data types, while ArrayLists cannot.
Arrays are part of the Java Collections Framework, while ArrayLists are not.
What is the result of the expression '10 % 3' in Java?
1
0
3.33
3
Why would you create a custom exception class in Java?
To modify the behavior of existing Java exception classes.
To avoid handling exceptions altogether.
To improve the performance of exception handling.
To represent specific exception scenarios relevant to your application.