Taller 10 demonstrates one of the most powerful ideas in object-oriented programming: polymorphism. When a parent-type reference holds a subclass instance, the JVM dispatches method calls to the subclass’s overridden implementation at runtime — not to the version declared in the variable’s compile-time type. The three exercises in this workshop build intuition for that mechanism, show it applied to real domain hierarchies, and then deliberately break it to reveal the overloading-vs-overriding pitfall that trips up even experienced developers.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Jhaymayleth/unidad2_java/llms.txt
Use this file to discover all available pages before exploring further.
Exercises
Ejercicio 1: Persona Polymorphism
PersonaT10 references holding EstudianteT10 and ProfesorT10 objects dispatch
to the correct overridden
presentarse() at runtime.Ejercicio 2: VehiculoT10 & BicicletaT10
Override
moverse() in BicicletaT10 and observe polymorphic behavior when
calling through a VehiculoT10 reference.Ejercicio 3: Override Pitfalls
See how a signature change silently creates an overload instead of an
override, and why omitting
@Override makes such bugs invisible.Key Concepts
@Override
The @Override annotation tells the compiler to verify that the annotated method actually overrides a method inherited from a superclass (or implements one declared in an interface). If the signatures do not match, the compiler fails immediately — preventing silent overload bugs.
Dynamic Dispatch
Java resolves overridden method calls at runtime based on the actual type of the object, not the declared type of the reference variable. This is called dynamic dispatch (or virtual dispatch):p is typed as PersonaT10, but because the object stored in it is an EstudianteT10, the JVM invokes EstudianteT10’s version of presentarse().
Overloading vs Overriding
| Overloading | Overriding | |
|---|---|---|
| Definition | Same method name, different parameter list | Same method name and same parameter list, in a subclass |
| Resolved at | Compile time | Runtime |
| Polymorphism | ❌ Static — no dynamic dispatch | ✅ Dynamic — enables polymorphism |
@Override annotation | Would cause a compile error | Strongly recommended |
Compile & Run
All classes live in theTaller10 package. Compile from the project root: