Taller 9 focuses on theDocumentation 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.
super keyword — how to call a parent class constructor from a subclass constructor, how to invoke an overridden parent method from within a subclass method, and what the Java compiler rejects when super is used incorrectly. Working through these three exercises gives you a concrete picture of how the JVM wires parent and child class initialisation together and where the boundaries of super lie.
Ejercicio 1: Persona & Empleado
Chain constructors between
Persona and Empleado using super(nombre, edad), then delegate to the parent’s mostrarDetalles() via super.mostrarDetalles().Ejercicio 2: Animal & Pez
Extend
Animal with Pez, passing the especie argument up with super(especie) and enriching the output with the subclass-specific tipoDeAgua field.Ejercicio 3: super Pitfalls
See two deliberate compile-time errors: using
super inside a static method and trying to reach a private parent field directly through super.Key Concepts
super() in constructors
When a subclass constructor calls super(...), it delegates the initialisation of the inherited fields to the parent constructor. This call must be the first statement in the subclass constructor.
super.method() in instance methods
Inside an overriding instance method you can still run the parent’s version of that method by prefixing the call with super.:
Why super fails in a static context
super is a reference to the parent portion of the current object (this). Static methods do not have a this reference, so super is meaningless there and the compiler rejects it:
Private vs protected members
| Modifier | Subclass can read via super? |
|---|---|
public | ✅ Yes |
protected | ✅ Yes |
private | ❌ No — use a getter |
Compile & Run
All classes live in theTaller9 package. From the project root (the directory that contains the Taller9/ folder):