Created
October 19, 2023 14:29
-
-
Save alexaleluia12/363ee8984eebb33895a2ab746d5809fe to your computer and use it in GitHub Desktop.
Google PlayGround
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 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