ProgrammingModerateProduct-company placement · Java

What is printed?

What is printed?
Set<String> s = new HashSet<>();
System.out.print(s.add("a") + " " + s.add("a") + " " + s.remove("b") + " " + s.size());
  1. A. true false false 1
  2. B. true true false 2
  3. C. true false true 1
  4. D. false false false 1

Correct answer: A. true false false 1

add returns whether the set changed (false for a duplicate) and remove returns whether the element was present.

More OOP with C++ and Java questions

Exams that ask this topic