Java SE 8 Programmer II — Question 142
Given:
public interface Moveable<Integer> {
public default void walk (Integer distance) {System.out.println("Walking");) public void run(Integer distance);
}
Which statement is true?
Answer options
- A. Moveable can be used as below: Moveable<Integer> animal = n - > System.out.println("Running" + n); animal.run(100); animal.walk(20);
- B. Moveable can be used as below: Moveable<Integer> animal = n - > n + 10; animal.run(100); animal.walk(20);
- C. Moveable can be used as below: Moveable animal = (Integer n1, Integer n2) -> n+ n2; animal.run(100); animal.walk(20);
- D. Movable cannot be used in a lambda expression.
Correct answer: A
Explanation
Option A is correct because it properly implements the Moveable interface with a lambda expression for the run method while using the default walk method. Options B and C do not comply with the method signatures defined in the interface, and option D is incorrect since the Moveable interface can be utilized in a lambda expression.