Java Language Tutorial:

Java Language Dynamic Method Dispatch

Introduction

What is Dynamic Method Dispatch?

Dynamic Method Dispatch is a process in which the call to an overridden method is resolved at runtime rather than at compile-time. When an overridden method is called by a reference, Java determines which version of that method to execute based on the type of object it refer to. This is also know as runtime polymorphism.

We will see this through an example.

Remarks

  • Dynamic Binding = Late binding
  • Abstract classes cannot be instantiated, but they can be sub-classed (Base for a child class)
  • An abstract method is a method that is declared without an implementation
  • Abstract class may contain a mix of methods declared with or without an implementation
  • When an abstract class is sub-classed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract
  • Dynamic method dispatch is a mechanism by which a call to an overridden method is resolved at runtime. This is how java implements runtime polymorphism.
  • Upcasting : Casting a subtype to a supertype, upward to the inheritance tree.
  • Runtime Polymorphism = Dynamic Polymorphism

Java Language Dynamic Method Dispatch Examples:

Related Java Language Tutorial Topics:

Other Tutorial Topics:

This modified content is an extract of the original Stack Overflow Documentation released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow. This topic was created and modified by the Stack Ovedrflow Contributor.