Given:

interface Doable {

    public void doSomething(String s);
}

Which two class definitions compile?

A.

public abstract 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 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) {
    }
}

题解

选项 A,虽然 Task 类别没有实作出 Doable 界面的 doSomething 方法,但是 Task 类别为抽象类别,因此允许未实作的方法。

选项 B,抽象方法不能有程序实作区块。

选项 C,Job 类别的 doSomething 方法传入的参数和 Doable 界面的 doSomething 方法不同,将不被认为是实作 Doable 界面的 doSomething 方法,所以 Job 类别会因没有实作 Doable 界面的 doSomething 方法而无法编译。

选项 D,错误理由同选项 C。

选项 E,有成功实作出 Doable 界面的 doSomething 方法。