16.3 Declaring a Kotlin Class
Before an object can be instantiated, we first need to define the class ‘blueprint’ for the object. In this chapter we will create a bank account class to demonstrate the basic concepts of Kotlin object oriented programming.
In declaring a new Kotlin class we specify an optional parent class from which the new class is derived and also define the properties and methods that the class will contain. The basic syntax for a new class is as follows:
class NewClassName: ParentClass {
// Properties
// Methods
}
The Properties section of the declaration defines the variables and constants that are to be contained within the class. These are declared in the same way that any other variable would be declared in Kotlin.
The Methods sections define the methods that are available to be called on the class and instances of the class. These are essentially functions specific to the class that perform...