Java SE 8 Programmer II — Question 29

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?

Answer options

Correct answer: C

Explanation

Option C is correct because it creates an instance of Car through the Rideable interface and successfully calls the getCar method. Option A has incorrect syntax for instantiating a Car object. Option B tries to use a Car instance to invoke getCar, which is not valid since getCar is defined in the Rideable interface. Option D incorrectly attempts to call getCar directly on the Rideable interface, which is not possible.