

Even then, you can only access the member from within the original or derived class, it doesn't become public in the derived class. So you can think of it as " public for the class and derived classes, but private for all others.Ģ) internal extends protected to any class in any namespace in the same Assembly: in practice it means "anywhere in this EXE or DLL file" since an Assembly can contain multiple namespaces.ģ) protected internal extends internal to classes which derive from the original class, even if they are outside the current namespace and assembly.ġ) You can't unless you derive a class from the original class which declare the protected member. Here is a table from the Kotlin in Action book that summarises these modifiers.1) protected means that the code can be accessed from any class derived from the original class. You can only create an extension function of a public class Summary With private declarations are only visible in the class as in Java but in Kotlin also in the file (top level declarations) where it is declared.Īnother difference is that in Kotlin outer classes do not see private nested (or inner) classes protectedĭeclarations are only visible in its class and in its subclassess Note: Extension FunctionsĮxtension functions don’t get access to its private or protected members. External code can define classes in the package you are trying to protect. Internal provides real encapsulation for the implementation details, while in Java’s package-private encapsulation could be broken. modules can be: maven projects, gradle sets, files generated from an Ant task, or a IntelliJ IDEA module internal means that the declarations are visible inside a module.Ī module in kotlin is a set of Kotlin files compiled together. Internal is an alternative to Java’s package-private. In Kotlin the default visibility modifier is public while in Java is package-private. The public modifiers means that the declarations are visible everywhere. Visibility modifiers control which declarations are visible from others.

“Man on a safari expedition looking through binoculars” by Louis Blythe on Unsplash
