Java OCA OCP Practice Question 3117

Question

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

a) @FunctionalInterface/*from w  w w. j a v a 2s.  c om*/
    interface Foo {
        void execute();
    }

b) @FunctionalInterface
    interface Foo {
        void execute();
        boolean equals(Object arg0);
    }

c) @FunctionalInterface
    interface Foo {
        boolean equals(Object arg0);
    }

d) interface Foo{}


a)    
b)

Note

the interface in option a) declares exactly one abstract method and hence it is a functional interface.

In option b) note that equals() method belongs to Object class, which is not counted as an abstract method required for a functional interface.

hence, the interface in option b) has only one abstract method and it qualifies as a functional interface.

option c) the interface does not have an abstract method declared and hence it is not a functional interface.

option d) the interface does not have any methods and hence it is not a functional interface.




PreviousNext

Related