kotlin abstract class code example
Example 1: kotlin class
class Person(val name: String, var age: Int)
Example 2: make abstrat classes kotlin
abstract class Person(name: String) {
init {
println("My name is $name.")
}
fun displaySSN(ssn: Int) {
println("My SSN is $ssn.")
}
abstract fun displayJob(description: String)
}
class Teacher(name: String): Person(name) {
override fun displayJob(description: String) {
println(description)
}
}
fun main(args: Array<String>) {
val jack = Teacher("Jack Smith")
jack.displayJob("I'm a mathematics teacher.")
jack.displaySSN(23123)
}