> For the complete documentation index, see [llms.txt](https://gold.gitbook.io/kotlin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gold.gitbook.io/kotlin/class/inheritance.md).

# inheritance

* Kotlin enum에서는 상태를 만들고 아래의 방식으로 추상화를 시킬 수 있다.
* abstract 로 멤버함수를 만들면 enum 안에있는 하나하나의 각 클래스들은 abstract 함수를 무조건 구현을 해야한다.
* 외부에서 접근할때는 ProtocolState.WAITING.signal() 이런식으로 접근이 가능하다.

```kotlin
enum class ProtocolState {
    WAITING {
        override fun signal() = TALKING
    },

    TALKING {
        override fun signal() = WAITING
    };

    abstract fun signal(): ProtocolState
}

println(ProtocolState.WAITING)    //WAITING
println(ProtocolState.TALKING)    //TALKING        

println(ProtocolState.WAITING.signal())    //TALKING
println(ProtocolState.TALKING.signal())    //WAITING
```

* Kotlin의 class는 기본적으로 final 이다.
* final class는 상속이 되지 않는다.
* override할 메소드에는 override키워드를 붙여준다. (Java에서의 @Override와 동일)
* 상속가능한  class를 만드려면 open, abstract키워드를 사용한다.
* open과 abstract 모두 Java의 abstract와 비슷하다.
* open class는 instance를 생성 할 수 있지만 abstract class는 instance를 생성 할 수 없다.
