Answers for "kotlin inheritance"

4

kotlin inheritance

open class Person(age: Int, name: String) {
    init {
        println("My name is $name.")
        println("My age is $age")
    }
}

class MathTeacher(age: Int, name: String): Person(age, name) {
    fun teachMaths() {
        println("I teach in primary school.")
    }
}

class Footballer(age: Int, name: String): Person(age, name) {
    fun playFootball() {
        println("I play for LA Galaxy.")
    }
}

fun main(args: Array<String>) {
    val t1 = MathTeacher(25, "Jack")
    t1.teachMaths()
    println()

    val f1 = Footballer(29, "Christiano")
    f1.playFootball()
}
Posted by: Guest on April-21-2021
1

kotlin inheritance

open class A{
}
class B : A(){
}
Posted by: Guest on April-22-2021

Browse Popular Code Answers by Language