Created
June 9, 2023 07:43
-
-
Save kalaiselvan369/b3c8ef6a387c372ec70985c97c07ac23 to your computer and use it in GitHub Desktop.
Protected modifier usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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