Access modifiers

There are four visibility modifiers in Kotlin, private, protected, internal and public for the classes, objects, constructors, properties, functions interfaces, and setters of properties, they have the same visibility of the property. If you don’t define a modifier it will take the default case, public.

Public, protected and private are the same in Java.

Internal in:

  • Package: It will be visible inside the file containing the declaration.
  • Classes and Interfaces: Any client inside this module who sees the declaring class sees its internal members.
  • Modules: is a set of Kotlin files compiled this is the list:
  1. IntelliJ IDEA module.
  2. Maven project.
  3. Gradle source set.
  4. A set of files compiled with one invocation of the Ant task.

Also, if you override a protected member and do not specify the visibility explicitly, the overriding member will also have protected visibility.