Skip to main content

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.

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.

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.
@Override
public void presentarse() {          // ✅ compiler confirms PersonaT10 has this signature
    System.out.println("Hola, soy " + nombre + " y estudio " + carrera + ".");
}

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):
PersonaT10 p = new EstudianteT10("Pedro", "Diseño Gráfico");
p.presentarse(); // Dispatches to EstudianteT10.presentarse(), not PersonaT10.presentarse()
The variable 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

OverloadingOverriding
DefinitionSame method name, different parameter listSame method name and same parameter list, in a subclass
Resolved atCompile timeRuntime
Polymorphism❌ Static — no dynamic dispatch✅ Dynamic — enables polymorphism
@Override annotationWould cause a compile errorStrongly recommended

Compile & Run

All classes live in the Taller10 package. Compile from the project root:
# Compile all Taller 10 sources
javac Taller10/*.java

# Run each exercise
java Taller10.MainEjercicio1T10
java Taller10.MainEjercicio2T10
java Taller10.MainEjercicio3T10

Build docs developers (and LLMs) love