#56 Dynamic Method Dispatch in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

in this video we are discussing method dispatch

-- in previous lecture we had discussed what is polymorphism
-- in this lecture we are further talking about run time polymorphism
-- suppose we have some class A , B and C
-- class B and C extends A
-- in All three class we have show() method
-- main() method of Demo we create object of A, B and C but we create only reference of A which can hold
object of A, B and C .
class A{
public void show(){
}
}
class B extends A{
public void show(){
}
}

class C extends A{
public void show(){
}
}

public class Demo{
public static void main(String []args){
A obj =new A();

obj =new B(); //reference is A (we can use reference of parents) and create object of B and assign to parents reference variable.

obj =new B(); //reference is A (we can use reference of parents) and create object of C and assign to parents reference variable.


}
}

Note: during compile time we donot which show() method is called from which class.
-- we can know during run time which show method is called this is known as run time polymorphism.
-- all this concept is class dynamic method dispatch

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

Really you deserve a Dhrona Charya award sir. I've learn a from you than I had learnt from my college.

AchuStudies-cd
Автор

Sir you have God gifted knowledge no one can explain this clear thank you.

MohamedWasim-gheh
Автор

It is like episode of any web series.
I am excited to watch next episode after watching previous lacture.

Really too good sir .

AjayYadav-dfez
Автор

As am a Java Trainee Trainer Telusko videos are 💎

raghav
Автор

I’ve entered in 8th year of my corporate journey after passing out in 2015. I started now learning java with your amazing tutorials so that i can switch my domain in IT.

Gaurav_fit
Автор

Great place to learn or brush up java. Keep doing this great work sir.

yeshwanthreddy
Автор

Dynamic method dispatch is the mechanism by which the call to an overridden method is resolved at runtime rather than compile-time. This occurs when a superclass reference variable is used to refer to a subclass object, and the overridden method is called on that reference. The method to be executed is determined based on the actual object's type, not the reference variable's type.

onlysubscriptions
Автор

You said we don't know at the compile time which method will be called, But we know right, the method inside the class whose object is actually created, will be executed. So how exactly is this run time polymorphism.

kilvish
Автор

The best explaination ever in few minutes. Thanku sir for the best explanation.

bhabagrahibarik
Автор

Very interesting. Thank you very much. I'd like to know now: what element is polymorphic now: the variable obj? The method show()? The type? The Object?

mackensonreginaldmichel
Автор

new Sir your videos are too easy to understand and right now I have completed some main topics which will help me in exams thank you

Sweetcorn-hf
Автор

easy to understand! you are my saver!!

蹦太君-od
Автор

The example of laptop and computer is best.

LAHUBUKKAM
Автор

that was an beautiful explanation. you earned a sub

avichiii
Автор

Thanks a lot sir for ez understanding series💖

k.kanimation
Автор

Lets say there is a class A and class B (without inheritance), so to create objects we say { A obj = new A(); B obj2 = new B() }, now obj and obj2 are variables referring to objects (but what it actually holds is an address location), does it mean different classes have different type of address location?

shreedharmakr
Автор

Sir will this work if B extends A and C extends B. Is it possible to call show method of class A from C

chakkers
Автор

Then what is the difference between function overriding and polymorphism sir?

sreeramv
Автор

Excellent explanation, I just noticed you look a little bit like Nacho from Better Call Saul :)

agariogg
Автор

When i give method name as show1() in class B and method name as show2() in class C and when I create object for B and and try to access the particular methods of particular classes it is not working. but it is working only when all the method names in all classes is show(). this is how i called method in B class
obj=new B();
obj.show1();
@Telusko Please give me clarity on this, I was bit confused

KishoreSumanjigari-jy