xxxxxxxxxx
class Person(val firstName: String, var age: Int) {
// class body
}
xxxxxxxxxx
class SmartDevice(val name: String, val category: String) {//Primary constructor. Can be instantiated without parameters.
var deviceStatus = "online"
//Secondary constructor "of type primary constructor (this)"
//Required to provide primary constructor parameters if applicable.
constructor(name: String, category: String, statusCode: Int) : this(name, category) {
deviceStatus = when (statusCode) {
0 -> "offline"
1 -> "online"
else -> "unknown"
}
}
}
xxxxxxxxxx
class Log {
constructor(data: String) {
// some code
}
constructor(data: String, numberOfData: Int) {
// some code
}
}