Visibility Modifiers

Visibility Modifiers

Classes, objects, interfaces, constructors, functions, properties and their setters can have visibility modifiers. (Getters always have the same visibility as the property.) There are four visibility modifiers in Kotlin: private, protected, internal and public. The default visibility, used if there is no explicit modifier, is public.

Below please find explanations of these for different type of declaring scopes.

Packages

Functions, properties and classes, objects and interfaces can be declared on the "top-level", i.e. directly inside a package:

// file name: example.kt
package foo

fun baz() {}
class Bar {}
  • If you do not specify any visibility modifier, public is used by default, which means that your declarations will be visible everywhere;
  • If you m