開発環境
- macOS Mojave - Apple (OS)
- Windows 10 Pro (OS)
- IntelliJ IDEA CE(Community Edition) (IDE(統合開発環境))
- Kotlin (プログラミング言語)
Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 6(abstract classes and interfaces - Serious Polymorphism)、Pool Puzzle(167)の解答を求めてみる。
コード
abstract class Appliance {
var pluggedIn = true
abstract val color: String
abstract fun consumePower(): Unit
}
class CoffeeMaker : Appliance() {
override val color = ""
var coffeLeft = false
override fun consumePower(): Unit {
println("Consuming power")
}
fun fillWithWater(): Unit {
println("Fill with water")
}
fun makeCoffee(): Unit {
println("Make the coffee")
}
}
fun main() {
val c = CoffeeMaker()
c.consumePower()
c.fillWithWater()
c.makeCoffee()
}入出力結果
Consuming power Fill with water Make the coffee Process finished with exit code 0
0 コメント:
コメントを投稿