October 2018
Intermediate to advanced
370 pages
9h 15m
English
The following class declaration is an example of a default constructor, when all properties of the class are directly initialized in the class body:
class Person { var name: String = "Abid" var age : Int = 40 var height : Double = 6.0 }val person = Person()
If you don't create a constructor for your class, Kotlin creates a default constructor automatically. The default constructor is a zero-argument constructor, in which all properties of the Person class contain some fixed initial values. The default constructor is not a good approach for object-creation. The object may have different values during its lifetime, but it will always have the same initial value at the time of creation.
In the following example, a Person ...
Read now
Unlock full access