Visibility Modifiers

A visibility modifier (a.k.a access modifiers or access specifiers) is a concept not tied to any specific programming language. It is a language keyword that precedes a declaration and defines the scope from where it is visible -thus can be accessed. Visibility Modifiers are modifiers that when appended to a class, interface, property or function in Kotlin, would define where all it is visible and from where all it can be accessed. The setters of properties in Kotlin can have a separate modifier from the property. There are four visibility modifiers in Kotlin

      • private
      • protected
      • internal
      • public

Private

The declarations marked with the private modifier are visible inside the file/class containing the declaration.


Private

Protected

The declarations marked with the protected modifier are visible inside the file containing the declaration and subclasses. This modifier is not allowed for top-level declarations.


Protected

Internal

The declarations marked with the internal modifier are visible everywhere in the same module.


Internal

Public

The declarations marked with the public modifier are visible to everyone. public is the default visibility modifier in Kotlin (a declaration without explicit modifier will be public)


Public

 

Questions

I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉

Have a nice a day! 🙂

 


 

Follow and like us:
Click to rate this post!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published. Required fields are marked *