> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/java/default-method-and-static-method.md).

# Default method and static method

* interface에 default method, static method 추가 가능(원래는 abstract method만 가능했지만 JDK1.8부터 가능)

Why dafault method, static method are in interface?

-인터페이스에 새로운 메서드(추상 메서드)를 추가하기 어려움. 왜냐하면 추상메서드를 하나 추가하면 해당 인터페이스를 사용하는 모든 클래스들은 이 추상메서드를 구현해야한다. => 해결책 : default method.

```java
interface MyInterface {
    void method();
    void newMethod();//추상 메서드
}
```

```java
interface MyInterface {
    void method();
    default void newMethod(){}//몸통
}
```

-default method가 기존의 메서드와 충돌할 때의 해결책(당연한 것이지만 짚고 넘어가자)

1. 여러 인터페이스의 디폴트 메서드 간의 충돌 : 인터페이스를 구현한 클래스에서 디폴트 메서드를 오버라이딩한다.
2. 디폴트 메서드와 조상 클래스의 메서드 간의 충돌 : 조상 클래스의 메서드가 상속되고, 디폴트 메서드는 무시된다.
