Skip to main content

Visibility Modifiers in Kotlin

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.

Code Sample

  • Public: public val name = "Avijit"
  • Private: private val name = "Avijit"
  • Protected: protected val name = "Avijit"
  • Internal: internal val name = "Avijit"

Syntax

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