1Z0-809 practice question 9 of 25
Given: public interface Moveable { public default void walk (Integer distance) {System.out.println(“Walking”);) public void run(Integer distance); } Which statement is true?
Full set: 196 questionsThe Moveable interface is a functional interface because it declares exactly one abstract method, run. Therefore, it can be a target for a lambda expression. Option A correctly provides a lambda expression n -> System.out.println("Running" + n) for the run method. The code then correctly calls the implemented run method and the inherited default walk method on the instance animal. The use of a raw type Moveable is valid, though it may generate a compiler warning.
B: The lambda n -> n + 10 has a return value, which is incompatible with the run method's void return type, causing a compilation error. C: The call Moveable.walk(20) is invalid. walk is a default (instance) method, not a static method, and must be invoked on an object instance (e.g., animal.walk(20)). D: This is incorrect. An interface with a single abstract method is a functional interface and can be implemented using a lambda expression.
- The Java™ Language Specification, Java SE 8 Edition, Section 9.8, "Functional Interfaces". It states, "A functional interface is an interface that has just one abstract method (aside from the methods of Object)".
- The Java™ Tutorials, "Lambda Expressions". Oracle Corporation. This tutorial explains that a lambda expression can be used to represent an instance of a functional interface.
- The Java™ Language Specification, Java SE 8 Edition, Section 9.4.1, "Default Methods". It clarifies that default methods are instance methods.
Keep practicing
Take the free 1Z0-809 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-809 practice questions
- Question 2Given: class Student { String course, name, city; public Student (String name, String cou…
- Question 3Given: class Worker extends Thread { CyclicBarrier cb; public Worker(CyclicBarrier cb) { …
- Question 4Given the code fragment: Path file = Paths.get (“courses.txt”); // line n1 Assume the cou…
- Question 5Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: Path …
- Question 6Given the code fragment:List<String> empDetails = Arrays.asList(“100, Robin, HR”,“200, Ma…
- Question 7Given the code fragment: List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Pre…
