Ejercicio 2 reinforces the sameDocumentation 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 patterns from Ejercicio 1 in a different domain: the animal kingdom. Animal stores and displays a species name, while Pez specialises it as a fish by adding information about the type of water it lives in. The subclass constructor passes especie up to Animal via super(especie), and the overridden mostrarEspecie() method layers Pez’s own output on top of the parent’s output by calling super.mostrarEspecie() first. The result is a clean two-level display built without duplicating any logic from the parent.
The Animal Class
Animal is the base class. It holds a single especie field and exposes a mostrarEspecie() method that prints it.
Taller9/Animal.java
The Pez Class
Pez extends Animal and adds the tipoDeAgua field. Its constructor accepts both especie and tipoDeAgua, forwarding especie to Animal’s constructor with super(especie). The overridden mostrarEspecie() calls super.mostrarEspecie() to print the inherited species line, then appends the water-type line.
Taller9/Pez.java
Execution flow for pez1.mostrarEspecie()
Main Program
Taller9/MainEjercicio2.java
Expected output
Animal directly, so mostrarEspecie() prints only the species line — no water-type output because Pez’s override is not involved.