Question 1. Given this code fragment:
List<String> vitamins = new ArrayList<String>();
vitamins.add("A");
vitamins.add("B12");
vitamins.add("C");
vitamins.set(1,"B");
vitamins.add(1,"D");
System.out.println(vitamins);
What is the result?
a. [A, D, B, C]
b. [A, D, C]
c. [D, B, C]
d. [D, B12, C]
Question 2. Given this code fragment:
1. class Engine { }
2. public class App {
3. public static void main(String[] args) {
4. Engine e = new Engine();
5. Engine e1 = e;
6. e = null;
7. }
8. }
Which statement is true about this code?
a. It creates an object and the object is eligible for garbage
collection.
b. It creates an object and the object is not eligible for garbage
collection.
c. It creates two objects: e and e1. The e object is eligible for
garbage collection.
d. It creates two objects and both the objects are not eligible for
No comments:
Post a Comment