Course contentsShow
← Java
Lesson 460 of 2,87011. Polymorphism and Dynamic DispatchFree lesson

What is Dynamic Dispatch?

Understanding how the JVM selects which method implementation to invoke at runtime based on the actual object type.

What is Dynamic Dispatch?

You'll learn: How Java decides at runtime which version of an overridden method to execute based on the actual object type, not the reference type.

The Core Idea

Dynamic dispatch is the mechanism that makes polymorphism work. When you call a method on an object reference, Java doesn't just look at the reference type to decide which method to run—it looks at the actual object type at runtime. This is what allows a Dog to bark like a dog and a Cat to bark like a cat, even when both are stored in Animal references.

You've already seen this in action with upcasting: when you upcast a Dog to an Animal reference and call an overridden method, the Dog's version executes, not the Animal's version. That's dynamic dispatch at work.

Why "Dynamic"?

The word "dynamic" means the decision happens at runtime, not at compile time. The compiler knows you're calling a method that exists in the reference type, but the JVM waits until the program is running to check, "What kind of object is this really?" and then invokes the appropriate implementation.

Simple Analogy

Think of it like calling a restaurant. You dial the number (the method call), but which chef actually cooks your meal depends on which restaurant answers the phone (the actual object type), not what you wrote in your contacts list (the reference type).

Dynamic dispatch is the "secret sauce" that makes inheritance hierarchies useful—you can write code that works with superclass references but automatically gets subclass-specific behavior without any extra effort.

Key Takeaway: Dynamic dispatch is the JVM's runtime mechanism for selecting the correct overridden method implementation based on the actual object type, enabling true polymorphic behavior in Java.