Any - mother of all class. The mother of dragons or the very top of the hierarchy. So, every time you create a class, your class is implicitly inheriting from Any that contains methods which you can use which are equal(), hashcode(), and toString().
The class you create is final by default. It means it cannot be inherited by other classes. If you want it to be inherited, you must include the open keyword during class declaration.
syntax:
open class Mother(val param1: Type){ // statement }
class Child(val childParam1: Type): Mother(childParam1){ // statement}
Note: 
1. The Mother or super class you created has a one parameter. So, when you create a child that extends the Mother as super class, it will require that one parameter. So, the child is required to initialized this parameter. The best way to do is to use a parameter on a child and initialized that Child parameter to the Mother class.
2. If your child is not using a parameter in its primary constructor, you can use the secondary constructor and be sure to delegate it to the extending Mother using the super keyword instead of the this keyword.
=====================
open class Mother(val message: String){
    open fun displayMessageHere(){
        println("Mother: $message")
    }
}
class Child: Mother{
    private val theMessage: String
    constructor(val childMessage: String): super(childMessage){
        theMessage = childMessage
    }
    override fun displayMessageHere(){
        super.displayMessageHere()
        println("Child: $theMessage")
    }
}
fun main(){
    val child = Child("We will be having a dinner.")
    child.displayMessageHere()
}
=====================
Result:
Mother: We will be having a dinner.
Child: We will be having a dinner.
Note: 
1. The method displayMessageHere() is a member of the class Mother and was override in the Child class since it was required because of the open keyword. But take note also, that an overriding member can also be overriden because it is still open and not yet final. What you just did was to override it and did not declare as final. So, to close the method from overriding, you need to add a final keyword to the member to make it final.
    final override fun displayMessageHere(){ // statement }
2. Properties are members of the class too. Not just the function. Since you can override a function, you can override a properties too. It works the same way as long as the property have the same name and type. The value don't matter.
 syntax 1:
open class Mother{
    open val name: Type = value
}
class Child: Mother{
    override val name: Type = value
}
Note: You can change val to var during override but not vice versa. This is because in val, you just get a value but in var, you can do a get and set a value.
syntax 2:
open class Mother{
    open val name: Type = value
}
class Child(override var name: Type): Mother{
}
Note: You are allowed to place the override property in the primary constructor in your child class.
The moment we create an object or an instance of the Child class, the Mother class will run first before the Child class will be executed. So, avoid using open keyword in the constructors, init blocks and property initializers. Property initializers are not the property itself but it is kind of a block where you initialize those properties like an init block. In java, there is a static initializer and non static initializer. But it is safe to use open keyword in properties, functions and parameters in class header.
super - this keyword is used to access the properties and functions of the mother class. 
    super.displayMessageHere()
But if you have an inner class inside your Child class, you need to add an at sign and the Child class name after the super keyword. Assuming the at sign is /:/ since there is a problem when using it here in wattpad.
    super/:/Child.displayMessageHere()
When the member you want to access is shadowed in two or more of your extensions like a Mother class and an interface. Meaning the call out for the member is the same in which the compiler find it hard to differentiate between the two, you need to specify the class of that extension inside the angle brackets.
    super<Mother>.displayMessageHere()
    super<YourInterface>.displayMessageHere()
                                      
                                          
                                   
                                              YOU ARE READING
Kotlin Programming
RandomI have been trying to learn things online. I will put my notes in here. I put things in my own words and i do not copy their programs. I try to do things the right way so that i may learn. Below is the site where i study. Go check this out if you wa...
 
                                               
                                                  