Inheritance
Learn how Kotlin classes can inherit functionality from other classes.
Kotlin Code
Study the example and understand each part.
open class Animal {
fun eat() {
println("Animal is eating")
}
}
class Dog : Animal() {
fun bark() {
println("Dog is barking")
}
}
fun main() {
val dog = Dog()
dog.eat()
dog.bark()
}
Kotlin is commonly developed using Android Studio or IntelliJ IDEA. These examples can be used as a foundation for Android application development.
Key Concept
Kotlin classes are final by default. A class must be marked open before another class can inherit from it.
Expected Output / Result
Animal is eating Dog is barking
Finished this lesson?
Mark it complete to update your course progress.