
In this article, you have learned about the Kotlin visibility modifiers along with few examples. can be private, protected, internal and public. If you dont supply a visibility modifier, you get the default visibility level, which is public. But local declarations (local variables, functions, and classes) can’t have visibility modifiers. Visibility modifiers Kotlin allows you to enforce symbol visibility (which Python only does via underscore conventions) via visibility modifiers, which can be placed on symbol declarations.

Any other module in the system can define classes in the same package as your.

Here’s a statement coming from a Kotlin team member: The motivation for not having package protected access is very simple: it does not provide any real encapsulation. Access modifiers kotlinĪs the name suggests, the visibility modifier controls the visibility or accessibility of declarations (classes, objects, interfaces, constructors, functions, properties, and their setters). As written in the docs, there is no protected modifier for top-level entities like classes. If you are using the private modifier in the declaration then it will be visible inside that particular class or file containing the declaration. In this article, we will go through all the visibility modifiers supported by Kotlin 2. By default, the visibility modifier in Kotlin is public.
