Which statement is true?

Given:
public interface Moveable<Integer> {
public default void walk (Integer distance) {System.out.println(“Walking”);)
public void run(Integer distance);
}
Which statement is true?

Given:
public interface Moveable<Integer> {
public default void walk (Integer distance) {System.out.println(“Walking”);)
public void run(Integer distance);
}
Which statement is true?

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 n) – > System.out.println(n);
animal.run(100);
Moveable.walk(20);

D.
Movable cannot be used in a lambda expression.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


CompileTester

CompileTester

A

smh

smh

Please guide me how A is the answer. thank you

CompileTester

CompileTester

A – is the only option that compiles.
B – fails since “n->n+10” returns a value but it should implement the method run() correctly which returns void.
C – fails too. The method walk() isn’t static, so it can’t be called like Moveable.walk(20);
D – is false because a functional interface can have only one mehtod that isn’t static or default. In Moveable class it’s run() mehtod.
It has takes Integer as arg and returns nothing.
So the interface definition is correct.

Hope it helps

smh

smh

thank you. I will try to learn on your feedback.

smh

smh

A. correct answer. it also prints following:

Running100
Walking
BUILD SUCCESSFUL (total time: 0 seconds)