-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Programming Kotlin
By :

Usually not all functions or classes are designed to be part of your public API. Therefore, it is desirable to mark some parts of your code as internal and not accessible outside of the class or package. The keywords that are used to specify this are called visibility modifiers.
There are four visibility modifiers: Public, internal, protected, and private. If no modifier is given, then the default is used, which is public. This means they are fully visible to any code that wishes to use them.
Java developers will know that this contrasts to the Java default, which has package-level visibility.
Any top-level function, class, or interface that is defined as private
can only be accessed from the same file.
Inside a class, interface, or object, any private
function or property is only visible to other members of the same class, interface, or object:
class Person { private fun age(): Int = 21 }
Here, the function age()
would only be invokable...