

In this example, we have two classes Parent class and Child class. Private class M圜lass Kotlin visibility modifier example private so visible inside Example.kt only By default public so visible everywhere The visibility of each one of them is mentioned in the comments. In the following example we have a file Example.kt and we have declared a data member, few member functions and a class inside the file. Internal: visible inside the same module. Protected: Visible inside class and subclasses. If a data member or member function is declared private in a class then they are visible in the class only. Private: visible inside the file containing the declaration. Public: visible everywhere, this is the default visibility modifier in Kotlin which means if you do not specify the modifier, it is by default public. In this guide, we will learn about these visibility modifiers with the help of examples.


In kotlin we have four visibility modifiers – public, private, protected and internal. Visibility modifiers restrict the access of classes, interfaces, functions, properties, constructors etc.
