# 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를 생성 할 수 없다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gold.gitbook.io/kotlin/class/inheritance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
