//Two types of Polymorphism in kotlin ->Static and Dynamic open class A{ fun hello1(){ println("Hii from the base class") } fun sum(a:Int,b:Int):Int{ hello1() return a+b } } class B:A(){ fun hello(){ println("Hii form the sub class") } fun sum(a:Int,b:Int,c:Int):Int{ //Function overloading //Dynamic Polymorphism(Run time binding) hello() return a+b+c } } fun main() { val obj=B() val result=obj.sum(12,32,4) println(result) } ////Polymorphism Static or compile time polymorphism //open class Father { //we have to open a class for inheritance //Base class // open val car="Bmw" ////We have to open the variable we are overriding in the parent class //// fun carName(){ //// println("Father has a $car car.") //// } //} // //class child: Father() { //sub class // override val car="Audi" // //we have to override the variable of same name in the child class // fun carName(){ // println("Child has a $car car.") // println("Father has a ${super.car}.") // //we use super for accessing the variable in parent class // // with the same name as in the child class // } //} //fun main() { // val obj1=child() // obj1.carName() //// println(obj1.car) //} Am i correct?? Please respond
@sidharthsharma78975 ай бұрын
why do we get the answer from the class we have made object from, when the function name is same in both the classes in function overloading?
@Jawad_Ahmad_01 Жыл бұрын
method overloading is dynamic or static ??? (at 1.57 minute of this video)