Classes and Objects
Object State
Use a value stored inside an object.
Object State
ObjectState.kt
class ScoreBox(var score: Int) {
fun afterAdd(points: Int): Int {
return score + points
}
}
fun main() {
val points =
val box = ScoreBox(10)
val finalScore = box.afterAdd(points)
println("points=$points")
println("score=$finalScore")
}
class ScoreBox(var score: Int) {
fun afterAdd(points: Int): Int {
return score + points
}
}
fun main() {
val points =
val box = ScoreBox(10)
val finalScore = box.afterAdd(points)
println("points=$points")
println("score=$finalScore")
}
class ScoreBox(var score: Int) {
fun afterAdd(points: Int): Int {
return score + points
}
}
fun main() {
val points =
val box = ScoreBox(10)
val finalScore = box.afterAdd(points)
println("points=$points")
println("score=$finalScore")
}
state
Object state is data stored by an object and used by its methods.