Java OCA OCP Practice Question 2282

Question

Which of the following are valid functional interfaces? (Choose two.)

A.   interface CanClimb {default void climb() {}  
        static void climb(int x) {}} 

B.   interface CanDance {int dance() { return 5;}} 

C.   interface CanFly {abstract void fly();} 

D.   interface CanRun {void run(); 
        static double runFaster() {return 2.0;}} 

E.   interface CanSwim {abstract Long swim(); 
        boolean test();} 


C, D.

Note

To be a valid functional interface, an interface must declare exactly one abstract method.

Option A is incorrect, because CanClimb does not contain any abstract methods.

Next, all interface methods not marked default or static are assumed to be abstract, and abstract methods cannot have a body.

CanDance does not compile, making Option B incorrect.

Options C and D are correct answers because each contains exactly one abstract method.

Option E is incorrect because it contains two abstract methods, since test() is assumed to be abstract.




PreviousNext

Related