Java OCA OCP Practice Question 1000

Question

Which lambda can replace the MyConverter class to return the same value?

Choose all that apply

interface Converter { 
  String convert(double d); 
} 

class MyConverter implements Converter { 
  public String convert(double d) { 
    return "Poof"; 
  } 
} 
  • A. caller((e) -> "Poof");
  • B. caller((e) -> {"Poof"});
  • C. caller((e) -> { String e = ""; "Poof" });
  • D. caller((e) -> { String e = ""; return "Poof"; });
  • E. caller((e) -> { String e = ""; return "Poof" });
  • F. caller((e) -> { String f = ""; return "Poof"; });


A, F.

Note

Option B is incorrect because it does not use the return keyword.

Options C, D, and E are incorrect because the variable e is already in use from the lambda and cannot be redefined.

Additionally, option C is missing the return keyword and option E is missing the semicolon.




PreviousNext

Related