ProgrammingHardProduct-company placement · Java

What is printed?

What is printed?
List<Integer> a = new ArrayList<>(List.of(1, 2));
List<Integer> b = new LinkedList<>(List.of(1, 2));
System.out.print(a.equals(b) + " " + List.of(1, 2).equals(Set.of(1, 2)));
  1. A. true false
  2. B. false false
  3. C. true true
  4. D. false true

Correct answer: A. true false

List.equals is defined for any List with equal elements in the same order, whatever the implementation. A Set is never equal to a List.

More OOP with C++ and Java questions

Exams that ask this topic