OCA Java SE 8 Class Design - OCA Mock Question Class Design 7








Question

Choose the correct statement about the following code:

     1: public interface Printable { 
     2:   int amount = 10; 
     3:   public static void fillPaper(); 
     4:   public int print() { 
     5:     return 13; 
     6:   } 
     7: } 
  1. It compiles and runs without issue.
  2. The code will not compile because of line 2.
  3. The code will not compile because of line 3.
  4. The code will not compile because of line 4.
  5. The code will not compile because of lines 2 and 3.
  6. The code will not compile because of lines 3 and 4.




Answer



F.

Note

The interface variable amount is correctly declared, with public and static being assumed and automatically inserted by the compiler, so B is incorrect.

The method declaration for fillPaper() on line 3 is incorrect because the method has been marked as static but no method body has been provided.

The method declaration for print() on line 4 is also incorrect, since an interface method that provides a body must be marked as default or static explicitly.

F is the correct answer since this code contains two compile-time errors.