Visibility modifiers
Visibility modifiers define how your declarations are accessible from other classes and packages. In Kotlin you can use the same modifiers that are found in Java, private, protected, and public.
Private visibility modifiers restrict access to the same class or a file. And public opens the access to everybody, no matter where they are trying to access a member from.
Java also has a fourth visibility modifier, package-private, which is also a default visibility modifier (if you don’t specify a visibility modifier, then package-private is implicitly applied). Package-private in Java means that declarations are visible only inside the same package. It is easy to bypass this visibility modifier. In your code, you can declare ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access