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

Given:

interface Rideable {Car getCar (String name); }

class Car {

private String name;

public Car (String name) {

this.name = name;

}

}

Which code fragment creates an instance of Car?

    Correct Answer: C

    The correct answer is the option where Rideable is assigned to Car::new, and then the getCar method is called with the argument 'MyCar'. This works because Rideable is a functional interface with a single abstract method, getCar. By using Car::new, we are effectively implementing the getCar method to return a new Car instance. Therefore, when rider.getCar('MyCar') is called, it creates a new Car object with the name 'MyCar'.

Discussion
M_JawadOption: C

C is the Correct Answer

adnano1234

True...The interface must be functional

DarGrinOption: C

Why does it work? Rideable rider = Car::new; Class Car doesn't implement Interface Rideable! Can somebody explain it please

Syyyyyyyy

Rideable is a FunctionalInterface. Rideable rider = Car::new, assigns Car::new as rider's getCar() method. So when you call rider.getCar() you are calling Car::new.

asdfjhfgjuaDCVOption: C

C is the correct answer

r1muka5Option: C

Answer is C

WilsonKKerllOption: C

Answer is C.