日記
今日書いたコード
fun main() { val squareCabin = SquareCabin(6) with(squareCabin) { println("\nSquare Cabin\n============") println("Capacity: ${capacity}") println("Material: ${buildingMaterial}") println("Has room? ${hasRoom()}") } } abstract class Dwelling(private var residents: Int) { abstract val buildingMaterial: String abstract val capacity: Int fun hasRoom(): Boolean { return residents < capacity } } class SquareCabin(residents: Int): Dwelling(residents) { override val buildingMaterial = "Wood" override val capacity = 6 }
感想
継承とかwith
とか面白い見た目をしていて面白い.*1