Skip to content

Instantly share code, notes, and snippets.

@Sottti Sottti/Protected.kt
Last active Dec 3, 2018

Embed
What would you like to do?
// Protected.kt file
// Visible inside this file
private const val numberThree = 3
// Visible inside this file
private open class User() {
// Visible inside the User class and subclasses
protected val numberEight = numberThree.plus(5)
}
// Visible inside this file
private class Moderator() : User() {
// Visible inside the Moderator class
// numberEight is visible because Moderator is a subclass of User
private val numberEleven = numberThree.plus(numberEight)
}
// ERROR: protected modifier is not allowed for top level declarations
protected const val numberThree = 3
// ERROR: protected modifier is not allowed for top level declarations
protected class Staff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.