ProgrammingHardProduct-company placement · Java

What is printed?

What is printed?
List<Character> l = new ArrayList<>(List.of('a', 'b'));
System.out.print(l.contains('a') + " " + l.contains(97) + " " + l.indexOf((char) 98));
  1. A. true true 1
  2. B. true false 1
  3. C. true false 0
  4. D. false false 1

Correct answer: B. true false 1

contains and indexOf take Object: 'a' boxes to Character (found), 97 boxes to Integer (never equal to a Character), and (char) 98 is 'b' boxed to Character at index 1.

More OOP with C++ and Java questions

Exams that ask this topic