Created
August 4, 2020 07:57
-
-
Save Ayeeta/2f0b904968a70782b9649f73bbf9be4f to your computer and use it in GitHub Desktop.
About classes and inheritance in kotlin
This file contains 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
open class Car(val make: String, val model: String, val engineSize: String){ | |
open fun accelerate(){ | |
println("vroom vroom") | |
} | |
fun brake(){ | |
println("STOP") | |
} | |
fun reverse(){ | |
println("car reversing...") | |
} | |
} | |
class RallyCar(make: String, model: String, engineSize: String, var bodyType: String) : Car(make, model, engineSize){ | |
override fun accelarate(){ | |
println("vroom ...200mph") | |
} | |
} | |
//Creating an instance | |
val mitsubishiEvo = RallyCar("Mitsubishi Lancer Evolution", "Evolution X", "3.0cc", "Sedan") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment