Junior — Middle
Can you name access modifiers in Kotlin that are absent in Java?
sobes.tech AI
Answer from AI
In Kotlin, there is an access modifier internal, which is not present in Java. It restricts the visibility of elements within a single module (for example, a single Gradle module or IntelliJ module).
Also, Kotlin has protected for class members, like in Java, but in Kotlin, protected does not allow access from the same package, only from subclasses.
Example of using internal:
internal class InternalClass {
fun doSomething() {}
}
This class will only be visible within the same module, which helps better encapsulate code compared to Java, where only public, protected, private, and package-private visibility exist.