WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Inheritance

In this chapter we will learn the Inheritance

In Kotlin, the base class is named as “Any”, which is the super class of the ‘any’ default class declared in Kotlin

Kotlin also provides this functionality using one keyword known as ":".

import java.util.Arrays

open class ABC {
   fun think () {
      print("Oh!! i am welookups")
   }
}
class BCD: ABC(){ // inheritence happend using default constructor 
}

fun main(args: Array) {
   var  a = BCD()
   a.think()
}
 
Output
Oh!! i am welookups
we are creating two classes and override one of its function into the child class.
import java.util.Arrays

open class ABC {
   open fun luck () {
      print("Oh!! i am welookups ")
   }
}
class BCD: ABC() { // inheritance happens using default constructor 
   override fun luvk() {
      print("I Am from tutorial ")
   }
}
fun main(args: Array) {
   var  a = BCD()
   a.luck()
}
Java, Kotlin too doesn’t allow multiple inheritances.
I Am from tutorial