Ejercicio 1 introduces the two most common uses ofDocumentation 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 in a single, tightly scoped example. Persona is the parent class that holds a person’s name and age. Empleado extends it to add an employment department. Rather than re-initialising nombre and edad itself, Empleado passes those values straight up to Persona’s constructor via super(nombre, edad). When printing details, Empleado also delegates to Persona’s mostrarDetalles() before printing its own extra line, so the output is built cooperatively across both classes.
The Persona Class
Persona is a plain base class with two package-visible fields and a single method that prints them.
Taller9/Persona.java
nombre and edad use package-level (default) visibility, meaning they are accessible to any class in the same Taller9 package — including Empleado.The Empleado Class
Empleado extends Persona and adds the departamento field. The constructor calls super(nombre, edad) as its first statement, handing off the job of initialising the inherited fields to Persona. The overridden mostrarDetalles() method calls super.mostrarDetalles() first, then appends the department line.
Taller9/Empleado.java
How super.mostrarDetalles() Works
When empleado1.mostrarDetalles() is called, execution flows like this:
super.mostrarDetalles() call, Empleado would have to duplicate Persona’s print logic. Using super keeps the code DRY and guarantees that any future change to Persona.mostrarDetalles() is automatically reflected in Empleado.
Main Program
Taller9/MainEjercicio1.java