

The protected modifier allows visibility in its class and subclass only. The public modifier declaration can be placed at the top of the file. If the class, interface, and method are not specified with any modifier then by default its specifier is public. The public modifier is accessible from anywhere in the class. It is the default modifier in the kotlin language. The variable declared inside this class is accessible only in this class. It is accessible only within the specified file. It allows the declaration to be accessible only inside the block in which properties, fields, elements, and more are declared.

With the help of these modifiers, we apply the limitation on the accessibility of the class, method, and interfaces.Ī private modifier does not allow the data elements to be accessed outside the block. There are four types of visibility modifiers in kotlin similar to other programming languages: These modifiers are used in the class header and method body to put the restriction. The keywords which restrict the accessibility of properties in class, interface, methods, and property of kotlin in the application is known as visibility modifier. In this article, you will learn about the visibility modifier and its type. What is the visibility Modifier in Kotlin? | Kotlin Tutorial
