Site is currently on development mode

Kotlin for Android Developers: Visibility Modifiers

Last updated 1 year ago by Pablo Costa


What is a visibility modifier?

A visibility modifier (a.k.a access modifiers or access specifiers) is a concept not tied to any specific programming language. It is a language keyword that precedes a declaration and defines the scope from where it is visible -thus can be accessed. Visibility modifiers facilitate encapsulation.

There are four visibility modifiers in Kotlin: private, protected, internal and public. The default visibility modifier is public.

Local variables, functions, and classes cannot have visibility modifiers in Kotlin.


The declarations marked with the private modifier are visible inside the file/class containing the declaration.


The declarations marked with the protected modifier are visible inside the file containing the declaration and subclasses. This modifier is not allowed for top-level declarations.


The declarations marked with the internal modifier are visible everywhere in the same module.

Read full Article