Java SE 8 Programmer II — Question 38
Given:
interface Doable {
public void doSomething (String s);
}
Which two class definitions compile? (Choose two.)
Answer options
- A. public class Task implements Doable { public void doSomethingElse(String s) { } }
- B. public abstract class Work implements Doable { public abstract void doSomething(String s) { } public void doYourThing(Boolean b) { } }
- C. public abstract class Job implements Doable { public void doSomething(Integer i) { } }
- D. public class Action implements Doable { public void doSomething(Integer i) { } public String doThis(Integer j) { } }
- E. public class Do implements Doable { public void doSomething(Integer i) { } public void doSomething(String s) { } public void doThat (String s) { } }
Correct answer: C, E
Explanation
Option C is correct because it provides an implementation of the doSomething method with the correct name and signature, even though the parameter type is different. Option E is also correct as it correctly implements the doSomething method with the appropriate signature and includes additional methods. Options A and D do not implement the required method correctly, while B is abstract and does not provide a concrete implementation of the method.