private class PP {
private var i = 1
private fun privateF() {
i += 1
}
fun access() {
privateF()
}
}
class OC {
fun test() {
val pc = PP()
}
}
Here, why is it possible to create an object without private in the test() in the class OC?
There's no explanation for this, so I was looking for it. One person said the function is accessible because it's higher than the class. Another person said it's a function in the class, so it's basically public, but it's hidden, so it's possible because it's the same as private.
Please explain why it is possible.
I'm very curious because I have to understand how it works!!!
kotlin private
You can create if PP
and OC
are in the same file.
The scope of the top-level private is a file.
Try separating PP
or OC
into different files.
© 2024 OneMinuteCode. All rights reserved.