Taller 8 teaches how Java implements single inheritance using 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.
extends keyword, how subclasses chain constructors with super(), and what happens when you try invalid inheritance patterns. By working through four progressively richer exercises you will see how a subclass inherits fields and methods, adds its own state, calls the parent constructor exactly once as the first statement, and selectively overrides behaviour while still delegating to the parent via super.
Ejercicio 1 — Vehiculo → Coche
Define a
Vehiculo base class with protected fields, then extend it with Coche which adds numeroDePuertas and overrides mostrarInfo() by delegating to super.mostrarInfo() before printing its own line.Ejercicio 2 — Persona → Estudiante
Extend the
Persona base class with Estudiante. Demonstrates constructor chaining with super(nombre, edad) and overloaded constructors that accept an optional starting promedio.Ejercicio 3 — Empleado → Gerente
Override
calcularBono() in Gerente to compute a higher bonus (15% base salary + 2% per managed employee) while inheriting all of Empleado’s core fields and behaviour.Ejercicio 4 — Multiple Inheritance Pitfalls
See the exact compiler error produced by
class ClaseC extends ClaseA, ClaseB, understand why private fields are invisible even inside subclasses, and learn the two correct workarounds: interfaces and getters.Key concepts
| Concept | What it does |
|---|---|
extends | Declares that a class inherits from exactly one parent class |
super() | Calls the parent constructor — must be the first statement in the child constructor |
super.method() | Calls the parent’s version of an overridden method from inside the override |
@Override | Annotation that tells the compiler to verify the method signature actually matches a parent method |
protected fields | Fields that are accessible directly from subclasses (and the same package), unlike private fields which require getters even from child classes |
| Single-inheritance rule | Java allows extends from only one class per subclass, eliminating the diamond problem |
Compile & run commands
All source files live inside numbered packages. Compile from thetaller8 directory.
Ejercicio 1 — Vehiculo & Coche