ATHENA
Illustrated avatar of Alex MorganAlex MorganComputer Science
SAME IDEA, DIFFERENT VOICES

Compare Sources

How 3 of your resources explain polymorphism, side by side.

CONCEPT
SOURCES · CHOOSE 2–3
JAVA PROGRAMMING ESSENTIALS

One call, many behaviours

Chapter 8 · Polymorphism · p. 142

Compiler-checked: a declared supertype, with the JVM choosing the implementation at runtime.

A List<Shape> holds a Circle, a Square and a Triangle. One loop calls area() on each, and the JVM picks the right version. The declared type decides which calls are allowed; the actual object decides which code runs. Interfaces such as Payable extend this to unrelated classes.

List<Shape> shapes = List.of(new Circle(2), new Square(3));
for (Shape s : shapes) total += s.area(); // dynamic dispatch
Open p. 142 in reader
PYTHON FOR INTERMEDIATE LEARNERS

If it quacks like a duck

Chapter 7 · Duck Typing and Polymorphism · p. 118

Behaviour-first: duck typing means any object with the right method will do.

A function that calls item.area() works with any object that has an area method. Overriding still gives each subclass its own version, but Python checks for the method only at runtime. typing.Protocol can document the expected behaviour.

def total_area(items):
    return sum(item.area() for item in items)  # any object with area()
Open p. 118 in reader
OBJECT-ORIENTED PROGRAMMING FOUNDATIONS

The same idea in Java and Python

Chapter 4 · Polymorphism Across Languages · p. 87

Language-neutral: the same principle shown side by side in Java and Python.

Polymorphism lets one piece of code operate on many types. Java expresses it through a declared supertype resolved at runtime; Python through duck typing. Both depend on inheritance or interfaces for a shared type and on encapsulation to hide implementation details.

Open p. 87 in reader

Similarities

  • All sources describe one interface used with many object types.
  • All treat method overriding and dynamic dispatch as the core mechanism.
  • Each connects polymorphism to inheritance or interfaces as the source of a shared type.

Differences

  • Java Programming Essentials stresses compile-time checks: declared type versus actual type.
  • Python for Intermediate Learners leads with duck typing, where no shared parent is required.
  • OOP Foundations is language-neutral and explains why all four pillars are needed.

Prepared comparisons written for this demo, based on the sample pages cited above.