Tsallaka zuwa abun ciki
Justice Tech School

Visibility Modifiers

public is the default. private limits to the class or file, protected to subclasses and internal to the module.

Example
class Account { private var balance = 0
    fun deposit(n: Int) { if (n > 0) balance += n }
    fun show() = balance }
val a = Account(); a.deposit(50)
println(a.show())

Exercise

Hide from outside.

 var secret = 1

Quiz Test

What is the default visibility?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.