Which keyword is used to exit a loop prematurely in Java?
continue
exit
return
break
What will be the output of the following code snippet?
ArrayList<String> list = new ArrayList<>(); list.add("apple"); list.add("banana"); System.out.println(list.get(1));
IndexOutOfBoundsException
banana
null
apple
What is the result of the expression '10 % 3' in Java?
3.33
0
3
1
What is the process of calling a method in Java?
Defining the method body
Creating an object of the class
Using the method's name followed by parentheses
Declaring the method's return type
Which of these is a valid way to call a method named 'calculateArea' in Java?
calculateArea()
call calculateArea()
calculateArea;
Area.calculate()
What will happen if you try to access an element at an invalid index in an ArrayList?
It will return null.
It will throw an ArrayIndexOutOfBoundsException.
It will throw a NullPointerException.
The program will crash.
What is the difference between a class and an object in Java?
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.
A class is a blueprint, while an object is a physical entity.
What is the default value of an element in an array of type double?
double
undefined
0.0
Which keyword is used to define a block of code that might throw an exception?
try
finally
catch
throw
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.
Yes, but they must have the same parameter list.
No, a class can only have one constructor.