13 Initialization
In the last chapter, you saw how to define classes that represent real-world objects. In NyetHack, a player is defined in part by its properties and by its behavior. For all the complexity that can be represented using class properties and functions, you have seen very little so far of how instances of classes come to be.
Think back to how Player was defined in the last chapter.
class Player {
...
}
Player’s class header is quite simple, and, as such, instantiating Player was also simple.
fun main(args: Array<String>) {
val player = Player()
...
}
Recall that when you call a class’s constructor, an instance of that class is created – a process known as instantiation. This chapter covers the ways classes ...
Get Kotlin Programming: The Big Nerd Ranch Guide, First Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.