OCA Java SE 8 Method - OCA Mock Question Method 16








Question

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

     interface Printable { 
       String isPrintable(double d); 
     } 

     class MyPrintable implements Printable { 
       public String isPrintable(double d) { 
         return "Yes"; 
       } 
     } 
  1. myTester((e) -> "Yes");
  2. myTester((e) -> { String e = ""; "Yes" });
  3. myTester((e) -> {"Yes"});
  4. myTester((e) -> { String e = ""; return "Yes"; });
  5. myTester((e) -> { String e = ""; return "Yes" });
  6. myTester((e) -> { String f = ""; return "Yes"; });




Answer



A, F.

Note

C is incorrect because it does not use the return keyword.

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

B is missing the return keyword and option E is missing the semicolon.