공부
[Kotlin] interface 다중 상속시, 동명 메소드 override super<InterfaceA>.method() 로 사용
승가비
2022. 4. 22. 01:40
728x90
interface Bird {
val wings : Int
fun fly()
fun jump() { // 구현된 일반 메소드
println("Bird jump")
}
}
interface Horse {
val maxSpeed : Int
fun run()
fun jump() { // 구현된 일반 메소드
println("jump!, max speed : $maxSpeed")
}
}
class Pegasus : Bird, Horse {
override val wings : Int = 2
override val maxSpeed : Int = 100
override fun fly() {
println("The Pegasus Fly!")
}
override fun run() {
println("The Pegasus Run!")
}
override fun jump() {
super<Horse>.jump() {
println("The Pegasus jump")
}
}
}
[코틀린 완전정복] 추상 클래스와 인터페이스
추상 클래스? 인터페이스? 뭐가 다르지? 🤔
velog.io
728x90