Skip to content

Instantly share code, notes, and snippets.

@kalaiselvan369
Created June 9, 2023 07:43
Show Gist options
  • Save kalaiselvan369/b3c8ef6a387c372ec70985c97c07ac23 to your computer and use it in GitHub Desktop.
Save kalaiselvan369/b3c8ef6a387c372ec70985c97c07ac23 to your computer and use it in GitHub Desktop.
Protected modifier usage
fun main() {
val car = Car()
// although it is protected inside vehicle class while overriding it
// in the subclass we marked as public hence it is accessbile
car.start()
//car.engineStart() // not accessible since it is protected inside the car class
}
abstract class Vehicle {
protected abstract fun start()
protected fun engineStart() {
}
}
class Car: Vehicle() {
public override fun start() {
engineStart()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment