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));
null
banana
IndexOutOfBoundsException
apple
What will be the value of 'x' after executing the following Java code snippet?
int x = 5; x = x++ + ++x;
11
12
10
The code will result in a compilation error.
What is a potential risk of poorly implemented recursion?
StackOverflowError.
Slower execution speed.
Increased memory usage.
All of the above.
What is recursion in the context of Java methods?
Returning multiple values from a method
Calling a method from a different class
A method calling itself within its own definition
Overloading a method with different parameters
Which keyword is used to define a block of code that might throw an exception?
finally
throw
catch
try
What is the default value of an element in an array of type double?
double
0
0.0
undefined
Which of the following describes method overloading in Java?
Returning different data types from the same method
Defining multiple methods with the same name and different parameters
Calling a method from within itself
Changing the behavior of an existing method
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.
A class is a blueprint, while an object is a physical entity.
There is no difference; they are interchangeable terms.
A class is a variable type, while an object is a function.
What is the time complexity of the get() method for an ArrayList?
get()
O(log n)
O(1)
O(n log n)
O(n)
Why is method overloading useful?
To improve code readability
All of the above
To enhance code flexibility
To avoid code repetition