Java OCA OCP Practice Question 1549

Question

What is the result of compiling the following program?

package mypkg;/*from   ww w. ja  v a 2 s. c  o  m*/
 
interface Printable {
   public abstract void print();
}
@FunctionalInterface interface Displayable extends Printable {}  // k1

abstract class Shape implements Displayable {  // k2
   public abstract int toughness();
}
public class Rectangle extends Shape {  // k3
   public int toughness() { return 11; }
}
  • A. The code does not compile because of line k1.
  • B. The code does not compile because of line k2.
  • C. The code does not compile because of line k3.
  • D. The code compiles without issue.


C.

Note

both Printable and Displayable are functional interfaces since they contain exactly one abstract method, although only the latter uses the optional @FunctionalInterface annotation.

The declarations of these two interfaces, along with the abstract class Shape, compile without issue, making Options A and B incorrect.

The code does not compile, though, so Option D is incorrect.

The class Rectangle inherits two abstract methods, one from the interface Printable and the other from the abstract parent class Shape.

Since the class only implements one of them and the class is concrete, the class declaration of Rectangle fails to compile on line k3, making Option C the correct answer.




PreviousNext

Related