Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Created October 19, 2023 14:29
Show Gist options
  • Save alexaleluia12/363ee8984eebb33895a2ab746d5809fe to your computer and use it in GitHub Desktop.
Save alexaleluia12/363ee8984eebb33895a2ab746d5809fe to your computer and use it in GitHub Desktop.
Google PlayGround
fun main() {
val xaiomi = Foldable(isFolded=true, isScreenLightOn=false)
xaiomi.checkPhoneScreenLight()
xaiomi.switchOn()
xaiomi.checkPhoneScreenLight()
xaiomi.isFolded = false
xaiomi.switchOn()
xaiomi.checkPhoneScreenLight()
}
open class Phone(var isScreenLightOn: Boolean = false){
open fun switchOn() {
isScreenLightOn = true
}
fun switchOff() {
isScreenLightOn = false
}
fun checkPhoneScreenLight() {
val phoneScreenLight = if (isScreenLightOn) "on" else "off"
println("The phone screen's light is $phoneScreenLight.")
}
}
class Foldable(var isFolded: Boolean, isScreenLightOn: Boolean): Phone(isScreenLightOn) {
override fun switchOn() {
if(!isFolded) {
super.switchOn()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment