Skip to content

Instantly share code, notes, and snippets.

@Ayeeta
Created August 4, 2020 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayeeta/2f0b904968a70782b9649f73bbf9be4f to your computer and use it in GitHub Desktop.
Save Ayeeta/2f0b904968a70782b9649f73bbf9be4f to your computer and use it in GitHub Desktop.
About classes and inheritance in kotlin
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