Basic classes app and using the init block
You can get the completed code for this app in the code download. It is in the Chapter10/Basic Classes
folder. But it is most useful to read on to create your own working example.
We will create a few different classes using what we have learned throughout this chapter to put the theory in to practice. We will also see our first example of how classes can interact with each other by passing a class as a parameter into the function of another class. We know how to do this in theory already, we just haven't seen it in practice yet.
We will also see another way to initialize our data when the class is first instantiated by using an init
block.
We will create a small app that plays with the idea of simulating ships, docks, and sea battles.
Note
The output for the apps in this chapter and the next will be just text to the logcat window. In Chapter 12, Connecting our Kotlin to the UI and Nullability, we will bring together everything we learned in the first...