Question: 13. Consider the following code snippet. btOK.setOnAction(new EventHandler () { public void handle(ActionEvent e) { System.out.println(OK clicked); } }); The above code snippet can be

13. Consider the following code snippet.

btOK.setOnAction(new EventHandler() {

public void handle(ActionEvent e) {

System.out.println("OK clicked");

} });

The above code snippet can be replaced by all of the following: which is the best?

a. btOK.setOnAction((e) -> System.out.println("OK cliked"););

b. btOK.setOnAction((ActionEvent e) -> System.out.println("OK Clicked"));

c. btOK.setOnAction(e -> {System.out.println("OK Clicked");});

d. btOK.setOnAction(e -> System.out.println("OK cliked"););

18. Analyze the following code:

public class Test {

public static void main(String[] args) {

Test test = new Test();

test.setAction(() -> System.out.print("Action 1! ")); }

public void setAction(T t) {

t.m1();

}

}

interface T {

public void m1();

public void m2();}

#-note that the interface has more than one abstract methods (not a functional interface):

a. The program displays Action 1.

b. The program displays Action 1 two times

c. The program has a compile error because T is not a functional interface. T contains multiple methods. Lambda notation cannot be used

d. The program would work if you change t.m1() to t.m2().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!