#6.5 Java Tutorial | Dynamic Method Dispatch

Описание к видео #6.5 Java Tutorial | Dynamic Method Dispatch

In this lecture we are discussing:
1)Loose coupling (Dynamic method dispatch)
2)compile time polymorphism vs runtime polymorphism
3)Benefits of Dynamic method dispatch

#1
loose coupling - using parents type reference and child type object.

Suppose we have three Class A,B and C here B and C are child of A.
in A there are show() method and both class B and c override show() method.

class Main {
public static void main(){
//link this at run time
A obj1 =new B(); //loose coupling
obj1.show(); //this is linking at run time that’s why method overriding is called run time polymorphism
obj1 =new B(); //Dynamic method Dispatch
}
}

class A{
public void show(){System.out.println("this is parent");}
}

class B extends A{
public void show(){System.out.println("This is child B");}
}

class C extends A{
public void show(){System.out.println("this is child c");}
}

Since, during runtime show() method get selected for execution and every time we changing object and therefore method get changed at runtime this is known as dynamic method dispatch.

#2
:-- method overloading is compile time polymorphism, because linking of method get happen during compile time with object.
:-- method overriding is run time polymorphism because linking of method occur during runtime.

#3
benefit of loose coupling:

:--During enterprise level software we are working with loose coupling that time dynamic method dispatch really helpful.
:--Loose coupling allows making changes in the code easily.
:--Testing of loosely coupled structures is easier than the tightly coupled structure.
:--Less amount of code is required to make changes in a loosely coupled structure than in a tightly coupled structure.

Instagram :   / navinreddyofficial  
Linkedin :   / navinreddy20  
Discord :   / discord  

More Learning :

Java - https://bit.ly/3xleOA2
Python :- https://bit.ly/3H0DYHx
Django :- https://bit.ly/3awMaD8
Spring Boot :- https://bit.ly/3aucCgB
Spring Framework :- https://bit.ly/3GRfxwe

Servlet & JSP :- https://bit.ly/3mh5CGz
Hibernate Tutorial :- https://bit.ly/3NWAKah
Rest API | Web Service Tutorial :- https://bit.ly/38RJCiy

Git :- https://bit.ly/3NUHB3V
JavaScript :- https://bit.ly/3mkcFys
Kotlin :- https://bit.ly/3GR2DOG


Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
http://www.telusko.com/contactus

Комментарии

Информация по комментариям в разработке