ATHENA
Object-Oriented Programming Foundations / Smart Reader
THE ATHENA LIBRARY

Object-Oriented Programming Foundations

Selam Tesfaye & R. Lindqvist · textbook

Chapter 4 · Polymorphism Across Languages

The same idea in Java and Python

Polymorphism means that a single piece of code can operate on objects of many types. In Java, this is expressed through a declared supertype — an abstract class or an interface — and resolved at runtime by dynamic dispatch. In Python, it is expressed through duck typing: any object with the required method will do.

Both languages support subtype polymorphism through method overriding. Java adds compile-time checks and method overloading; Python favours runtime flexibility, with Protocols available when an explicit contract helps readers and tools.

Polymorphism depends on the other pillars. Without inheritance or interfaces there is no shared type; without encapsulation, callers would rely on internal details that differ from one implementation to another. Understanding polymorphism therefore means understanding how all four pillars work together.

Different languages, one principle: depend on behaviour, not on concrete types.

Fictional educational sample written for the Athena demo · Page 87 of 298.

100%saved