Java OCA OCP Practice Question 731

Question

What does the following output?

Predicate clear = c -> c.equals("clear"); 
System.out.println(clear.test("pink")); 
  • A. true
  • B. false
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


B.

Note

While it is common for a Predicate to have a generic type, it is not required.

When the generic is omitted, it is treated like a Predicate of type Object.

Since the equals() method exists on Object, this is fine.

Option B is correct because the Predicate tests as false.




PreviousNext

Related