Skip to content

Instantly share code, notes, and snippets.

@TerryJung
Created July 25, 2023 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerryJung/fd100499ddfbe3c5359d814a5c3afe66 to your computer and use it in GitHub Desktop.
Save TerryJung/fd100499ddfbe3c5359d814a5c3afe66 to your computer and use it in GitHub Desktop.
Kotlin 예제
open class Bus {
var departure = "서울"
var arrive = "부산"
fun engineStart() {
println("부릉부릉")
}
open fun departure() {
println("출발합니다")
println("$departure 에서 $arrive 로 출발합니다")
}
}
class ExpressBus : Bus(), Vehicle {
override fun departure() {
super.departure()
}
override fun putOil() {
println("경유 기름을 넣었습니다")
}
}
class WideBus : Bus(), Vehicle {
val stop1 = "판교"
val stop2 = "두정역"
override fun departure() {
super.departure()
println("정차 정류장은 $stop1 - $stop2 입니다")
}
override fun putOil() {
println("경유 기름을 넣었습니다")
}
}
class CityBus : Bus(), Vehicle {
val stop1 = "신림역"
val stop2 = "신도림역"
val stop3 = "홍대입구역"
override fun departure() {
super.departure()
println("정차 정류장은 $stop1 - $stop2 - $stop3 입니다")
}
override fun putOil() {
println("경유 기름을 넣었습니다")
}
}
interface Vehicle {
fun putOil()
}
class Avante : Vehicle {
override fun putOil() {
println("휘발유 기름을 넣었습니다")
}
}
fun main() {
val terminal = arrayListOf<Bus>()
val seoulToBusanBus = ExpressBus()
seoulToBusanBus.departure = "서울"
seoulToBusanBus.arrive = "부산"
terminal.add(seoulToBusanBus)
val seoulToCheonanBus = WideBus()
seoulToCheonanBus.departure = "서울"
seoulToCheonanBus.arrive = "천안"
terminal.add(seoulToCheonanBus)
terminal.forEach {bus ->
bus.engineStart()
bus.departure()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment