WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Inheritance

In this chapter, we will look about inheritance.

OOPS, Kotlin also provides this functionality using one keyword known as ":".the base class is named as "Any", which is the super class of the 'any' default class declared in Kotlin.
import java.util.Arrays

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

fun main(args: Array<String>) {
   var  a = BCD()
   a.think()
}

code will yield the following output in the browser.

Hey!! i am thiking 
when you override the think() method in the child class. we are creating two classes and override one of its function into the child class.
import java.util.Arrays

open class ABC {
   open fun think () {
      print("Hey!! i am thinking ")
   }
}
class BCD: ABC() { // inheritance happens using default constructor 
   override fun think() {
      print("I Am from Child")
   }
}
fun main(args: Array<String>) {
   var  a = BCD()
   a.think()
}
I Am from Child