Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 238

Given:

public interface Moveable {

public default void walk (Integer distance) {System.out.println("Walking");) public void run(Integer distance);

}

Which statement is true?

Moveable can be used as below:

A.

Moveable animal = n - > System.out.println("Running" + n); animal.run(100); animal.walk(20);

Moveable can be used as below:

B.

Moveable animal = n - > n + 10;

animal.run(100);

animal.walk(20);

Moveable can be used as below:

C.

Moveable animal = (Integer n) - > System.out.println(n);

animal.run(100);

Moveable.walk(20);

Movable cannot be used in a lambda expression.

D.

    Correct Answer:

    The correct answer is A. The Moveable interface can use a lambda expression to implement the run method, which matches the functional interface pattern. In the option A, the lambda expression 'n -> System.out.println("Running" + n)' correctly implements the run method. The run method is then called with 'animal.run(100)' and the walk method with 'animal.walk(20)'. This is valid because the walk method has a default implementation. Option B is incorrect because 'n -> n + 10' does not match the required method signature for run, as it does not implement the void run(Integer distance) method. Option C is incorrect due to the syntax error 'Moveable.walk(20);' instead of 'animal.walk(20);'. Option D is false because Moveable can indeed be used in a lambda expression.

Discussion
thetech

Answer is A. Tested.

asdfjhfgjuaDCV

Answer is A tested