[kotlin] 코틀린에서의 접근 제한자 사용 예시를 알려주세요.
1. Public
class Example {
public fun publicFunction() {
// 코드
}
}
2. Private
class Example {
private val privateVariable = 5
private fun privateFunction() {
// 코드
}
}
3. Protected
open class Parent {
protected open val protectedVariable: Int = 10
}
class Child : Parent() {
fun accessProtectedVariable() {
val value = protectedVariable
}
}
4. Internal
internal class InternalClass {
internal fun internalFunction() {
// 코드
}
}
5. 접근 제한자의 기본값
코틀린에서 접근 제한자를 명시적으로 지정하지 않으면 기본적으로 public
으로 적용됩니다.