Kotlin

Visibility Modifiers

Introduction#

In Kotlin, there are 4 types of visibility modifiers are available.

Public: This can be accessed from anywhere.

Private: This can only be accessed from the module code.

Protected: This can only be accessed from the class defining it and any derived classes.

Internal: This can only be accessed from the scope of the class defining it.

Syntax#

  • <visibility modifier> val/var <variable name> = <value>

Code Sample

Public: public val name = "Avijit"

Private: private val name = "Avijit"

Protected: protected val name = "Avijit"

Internal: internal val name = "Avijit"


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow