---
# System prepended metadata

title: abstract class和interface
tags: [ocpjp]

---

# abstract class和interface
```java=
interface Doable {
	public void doSomething (String s);
}
```
**Which two class definitions compile?**

### A.
```java=
public abstract class Task implements Doable {
    public void doSomethingElse(String s) {
    }
}
```
### B.
```java=
public abstract class Work implements Doable {
    public abstract void doSomething(String s) {
    } 
    public void doYourThing(Boolean b) {
    }
}
```
### C.
```java=
public class Job implements Doable {
    public void doSomething(Integer i) {
    }
}
```
### D.
```java=
public class Action implements Doable {
    public void doSomething(Integer i) {
    }
    public String doThis(Integer j) {
    }
}
```
### E.
```java=
public class Do implements Doable {
    public void doSomething(Integer i) {
    } 
    public void doSomething(String s) {
    } 
    public void doThat(String s) {
    }
}
```
:::warning
#### A. doSomethingElse與doSomething不同方法，但是本身是abstract class,所以可以有未實作的方法
#### B. 抽象方法不能有實作區塊
#### C. doSomething(Integer i)和doSomething (String s)是不同方法，不是抽象類別的話必須要實作Doable的doSomething (String s)
#### D. 跟C.原因一樣
#### E. 有實作Doable的doSomething(String s)

- [x] **Answer:AE**
:::

###### tags: `ocpjp`
