Java OCA OCP Practice Question 700

Question

What does the following do?

public class Shoot { 
  interface Printable { 
     boolean print(double angle); 
  } // ww  w . j  a v a2s  . co m
  static void prepare(double angle, Printable t) { 
     boolean ready = t.print(angle);  // k1 

      System.out.println(ready); 
   } 
   public static void main(String[] args) { 
      prepare(45, d -> d > 5 || d < -5);   // k2 
   } 
} 
  • A. It prints true.
  • B. It prints false.
  • C. It doesn't compile due to line k1.
  • D. It doesn't compile due to line k2.


A.

Note

This is a correct example of code that uses a lambda.

The interface has a single abstract method.

The lambda correctly takes one double parameter and returns a boolean.

This matches the interface.

The lambda syntax is correct.

Since 45 is greater than 5, Option A is correct.




PreviousNext

Related