October 2018
Intermediate to advanced
370 pages
9h 15m
English
In Kotlin, each class property is considered a first-class citizen, which we discussed in the Properties – A first class citizen section of Chapter 2, Introduction to Object-Oriented Programming. In this section, we will learn more about properties and how to define the getter and setter functions that are explicitly provided by Kotlin. Let's create a Person class with two properties, name and age:
class Person { var name: String = "" var age : Int = 0 }
Create an instance of the Person class. Assign some values to each property and display the values on the screen:
fun main(args: Array<String>) { val abid = Person() abid.name = "Abid Khan" abid.age = 40 println(abid.name) println(abid.age)}
When we assign a value ...
Read now
Unlock full access