October 2021
Intermediate to advanced
500 pages
16h 23m
English
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, so instantiating Player was also simple:
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 and their properties can be initialized. When ...
Read now
Unlock full access