OCA Java SE 8 Method - OCA Mock Question Method 17








Question

What is the result of the following code?

     1: interface Printable { 
     2:   boolean isPrintable(int height, int limit); 
     3: } 
     4:  
     5: public class Main { 
     6:    public static void main(String[] args) { 
     7:       check((h, l) -> h.isEmpty(), 5); 
     8:    } 
     9:    private static void check(Printable p, int height) { 
     10:     if (p.isPrintable(height, 10))  
     11:        System.out.println("printable"); 
     12:     else  
     13:        System.out.println("not printable"); 
     14:   } 
     15: } 
  1. not too high
  2. too high
  3. Compiler error on line 7.
  4. Compiler error on line 10.
  5. Compiler error on a different line.
  6. A runtime exception is thrown.




Answer



C.

Note

The interface takes two int parameters.

The code on line 7 attempts to use them as if one is a String.