Java OCA OCP Practice Question 2623

Question

Which of the following are valid functional interfaces? (Choose all that apply.)

public interface Printable { 
   public int print(); 
} 
public abstract class Writable { 
   public abstract Object write(double speed, int duration); 
} 
public interface ConsolePrintable extends Printable {} 

public interface LinuxConsolePrintable extends ConsolePrintable { 
   public default int getSpeed(); 

} 
A.   Printable
B.   Writable
C.   LinuxConsolePrintable
D.   ConsolePrintable
E.   None of these are valid functional interfaces.


A, D.

Note

A is correct as Printable defines an interface with exactly one abstract method.

B is incorrect, as abstract classes are not functional interfaces despite having a single abstract method.

While functional interfaces may have any number of default methods, LinuxConsolePrintable will not compile due to the default method getSpeed() missing an implementation body, so C is incorrect.

D is correct, as the interface ConsolePrintable has exactly one abstract method defined in Printable.

Finally, E is incorrect because A and D are correct.




PreviousNext

Related