Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Coroutine
- TEST
- androidStudio
- 코루틴
- Rxjava
- android
- Kotlin
- boj
- 프로그래머스
- Python
- ProGuard
- relay
- Codeforces
- 백준
- architecture
- 코드포스
- MyVoca
- GitHub
- Hilt
- activity
- textfield
- Coroutines
- pandas
- 쿠링
- Compose
- Gradle
- livedata
- 암호학
- AWS
- MiTweet
Archives
- Today
- Total
이동식 저장소
[Kotlin] abstract class 본문
Abstract class(이하 추상 클래스)는 인스턴스를 만들 수 없는 클래스이다. 추상 클래스는 보통 추상 메소드를 포함한다. 추상 메소드란 기본적으로 구현되지 않은 메소드이며 따라서 자식 클래스에서 구현되어야 한다. 추상 메소드는 항상 `open`이므로 별도로 `open` 키워드를 적을 필요는 없다.
abstract class Animated {
abstract fun animate()
open fun stopAnimate() {
// default implementation(기본 구현)을 가질 수 있음
}
fun animateAgain() {
// default implementation(기본 구현)을 가질 수 있음
}
}
위의 예시에서 `animate()`는 추상 메소드이다. 따라서 `Animated`에서 구현될 수 없으며 `Animated`의 자식 클래스가 반드시 구현해야 한다.
추상 메소드가 아닌 `stopAnimate()`와 `animateAgain()`은 기본 구현값을 가질 수 있으며, `open` 키워드를 사용하여 상속 가능하게 만들 수도 있다.
'Primary > Kotlin' 카테고리의 다른 글
| [Kotlin] sealed class (0) | 2022.05.20 |
|---|---|
| [Kotlin] Nested Class, Inner Class (0) | 2022.05.19 |
| [Kotlin] Inline class (0) | 2022.05.04 |
| [Kotlin] 코루틴의 실행 순서와 테스트 코드 (2) | 2022.04.26 |
| [Kotlin] Coroutine을 반환 vs. 그냥 실행 (1) | 2022.04.25 |
Comments