Two Class Definitions That Compile | 1Z0-809 Java SE 8 Programmer II

Which Class Definitions Compile for the Doable Interface? | 1Z0-809 Exam Question

Question

Given: interface Doable { public void doSomething (String s); } Which two class definitions compile? (Choose two.)

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

AE.

The given interface Doable has a single abstract method doSomething that takes a String parameter and returns void. To implement this interface, a class must provide a concrete implementation for the doSomething method. Let's examine each class definition and see if it correctly implements the Doable interface:

A. public class Task implements Doable { public void doSomethingElse(String s) { } } This class definition does not correctly implement the Doable interface because it provides a method doSomethingElse instead of the required doSomething method.

B. public abstract class Work implements Doable { public abstract void doSomething(String s) { } public void doYourThing(Boolean b) { } } This class definition correctly implements the Doable interface by providing a concrete implementation for the required doSomething method. It also provides an additional method doYourThing that is not part of the Doable interface but is allowed.

C. public abstract class Job implements Doable { public void doSomething(Integer i) { } } This class definition does not correctly implement the Doable interface because it provides a method doSomething that takes an Integer parameter instead of the required String parameter.

D. public class Action implements Doable { public void doSomething(Integer i) { } public String doThis(Integer j) { } } This class definition does not correctly implement the Doable interface because it provides a method doSomething that takes an Integer parameter instead of the required String parameter. It also provides an additional method doThis that is not part of the Doable interface but is allowed.

E. public class Do implements Doable { public void doSomething(Integer i) { } public void doSomething(String s) { } public void doThat (String s) { } } This class definition correctly implements the Doable interface by providing concrete implementations for the required doSomething method. It also provides an additional method doThat that is not part of the Doable interface but is allowed.

Therefore, the two class definitions that compile and correctly implement the Doable interface are B and E.