Column 1
Column 2
Column 3
100

What does the @Override annotation do, what happens if it is omitted?

The @Override annotation ensures that a method is correctly overriding a superclass method. If omitted, the code will still work but it may allow accidental method overloading instead of method overriding.

100

What will be the output of list.get(1)?

ArrayList<String> list = new ArrayList<>();

list.add("apple");

list.add("banana");

list.add("cherry"); 

banana

100

Which of the following can be overriden in a subclass? (Select all that apply) a. Static methods b. Instance methods c. Private methods

Only instance methods can be overriden. Static methods are hidden, and private methods are not inherited.

200

Is there an error with the following, and if so, what is it? ArrayList list = {0, 1, 2, 3}; System.out.println(list[3]);

Yes, you use .get() instead of [].

200

What will happen when you try to inherit from a final class and why does that happen?

A compilation error will be thrown because final classes cannot be extended. cannot inherit from final <classname>

200

What type of memory does recursion use?

Stack

300

Explain a solution to reverse a string using recursion.

Answers vary. One way is to take the first character, reverse the rest of the string, then add that character back to the end.

300

How would you combine the contents of list1 and list2 into a new ArrayList combinedList in one line?

ArrayList<String> list1 = new ArrayList<>();

list1.add("apple");

list1.add("banana");

ArrayList<String> list2 = new ArrayList<>();

list2.add("cherry");

list2.add("date");

addAll() method

300

Write a recursion for calculating n!, where we assume the factorial of negative integers is 1.

Answers vary.