Java OCA OCP Practice Question 719

Question

What does the following output?

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


C.

Note

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

It is treated like a Predicate of type Object if the generic type is missing.

Since startsWith() does not exist on Object, the first line does not compile, and Option C is correct.




PreviousNext

Related