Ejercicio 2 applies the same override-and-dispatch pattern to a vehicle domain.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.
VehiculoT10 provides a generic moverse() implementation, and BicicletaT10 replaces it with a description that is specific to how a bicycle moves. Assigning a BicicletaT10 instance to a VehiculoT10 variable and then calling moverse() through that variable confirms that the runtime type — not the variable type — controls which implementation executes.
Class Hierarchy
BicicletaT10 inherits the marca field from VehiculoT10 via super(marca) and overrides moverse() to reflect bicycle-specific locomotion (“pedaleando”).
Source Code
VehiculoT10.java
VehiculoT10 is the base class. Its moverse() prints a generic movement message using the vehicle’s brand name. Any concrete vehicle subclass that does not override this method will fall back to this default description.
BicicletaT10.java
BicicletaT10 extends VehiculoT10 and overrides moverse(). The @Override annotation ensures the compiler validates that the method signature matches the one declared in VehiculoT10. The body replaces the generic vehicle phrase with one that names the bicycle and its pedalling motion.
Polymorphic Dispatch Through a Parent-Type Reference
The key moment inMainEjercicio2T10 is:
v1 is typed as VehiculoT10, the object it holds is a BicicletaT10. Java’s dynamic dispatch resolves moverse() to BicicletaT10’s override at runtime.
Output of that single call:
Full main Method
moverse() directly on each concrete type to show the difference in output. The second block reassigns a BicicletaT10 to a VehiculoT10 reference (v1) to isolate and highlight the polymorphic dispatch.