October 2018
Intermediate to advanced
370 pages
9h 15m
English
The preferred private modifier is the most restrictive modifier. When the properties are declared with private access, they are not accessible from outside the class:
private var name : String
Let's take an example of the Person class and apply the private visibility modifier:
class Person(pName: String, pAge: Int, pHeight : Double ) { private var name : String = pName private var age : Int = pAge private var height : Double = pHeight init { require(name.trim().isNotEmpty()) {"Name should not empty"} require(age > 0 ) {"Age is not correct"} require(height > 0) {"Height is not correct"} } } fun main(args: Array<String>) { val person = Person("bob",40,6.1) println("Name ${person.name}, Age ${person.age} Height ${person.height}" ...Read now
Unlock full access