Browse OOP reference
Relationships and dispatch

What is dynamic dispatch?

On this page

Dynamic dispatch selects an implementation using runtime information about the receiver, and in some languages additional arguments. A Java reference typed as Shape can call draw() on a Circle and run Circle’s override. Compiler optimisations can eliminate the lookup while preserving that observable behaviour.

Worked example

Python
class Notice:
    def subject(self):
        return "Update"
    def header(self):
        return "Subject: " + self.subject()

class Reminder(Notice):
    def subject(self):
        return "Renewal due"

assert Reminder().header() == "Subject: Renewal due"

Python tutorial on classes

Explore class relationships in the OOP Playground

What is method overloading?How do modern languages approach object orientation?What is method overriding?

All OOP questions

Search ObjectFAQ