

In the declaration then it will be visible inside that particular file containing the declaration and also in the subclass of that particular class. While the private variableĬlass and this is the reason why it shows an error when we try to use this In the above example, we are having three private variables and one private class. ERROR: newCount is not accessible outside the Student class

In the declaration then it will be visible inside that particular class or file containing the declaration. In Kotlin, we have four visibility modifiers:īy default, the visibility modifier in Kotlin is So, the scope of visibility is defined with the help of visibility modifiers. In that example, the employee from the accounts department is not allowed to directly access the details of library department. Let’s take the previous example of a school management system. Visibility modifier or access specifier or access modifier is a concept that is used to define the scope of something in a programming language. In this blog, we will learn about various Visibility Modifiers or access specifiers like public, protected, internal, and private in Kotlin. In a programming language, the concept of Encapsulation is implemented with the help of access specifiers or access modifiers. The above process is called Encapsulation because all the information related to a particular department is grouped and no one is allowed to access it unless granted the access. The employee from the accounts department should first contact some officials from the library department and that officer will provide the required details. In this case, the accounts department should not be allowed to directly access the information of the library department.

But a situation may arise when an employee from the accounts department requires the information of the library department(maybe details of fine). All these departments have their information. In school, we have various departments like the accounts department, library department, faculty department, student department, etc. It is the process of wrapping up of data and information under a single unit.Ĭonsider an example of a school management system. Encapsulation is one of the important features of object-oriented programming.
