Basic classes
There are two main steps involved with classes. First, we must declare our class, and then we can bring it to life by instantiating it into an actual useable object. Remember, the class is just a blueprint, and you must use the blueprint to build an object before you can do anything with it.
Declaring a class
Classes can be of varying sizes and complexities depending upon what its purpose is. Here is the absolute simplest example of a class declaration.
Remember that we most often declare a new class in a file of its own with the same name as the class.
Note
We will cover some exceptions to the rule throughout the rest of the book.
Let's have a look at three examples of declaring a class:
// This code goes in a file named Soldier.kt class Soldier // This code would go in a file called Message.kt class Message // This code would go in a file called ParticleSystem.kt class ParticleSystem
Note
Note that we will do a full working project to practice at the end of this chapter. There...