



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Una introducción a la herencia en java, un concepto fundamental de la programación orientada a objetos. Se explica la definición de herencia, sus características clave, y se ilustra con ejemplos prácticos de código. El documento también destaca las ventajas de la herencia, como la reutilización de código y la extensibilidad.
Typology: Cheat Sheet
1 / 7
This page cannot be seen from the preview
Don't miss anything!




¿Qué es la herencia en Java?
Ejemplo práctico: Clase Padre class Animal { String nombre; int edad; public Animal(String nombre, int edad) { this.nombre = nombre; this.edad = edad; } public void hacerSonido() { System.out.println("El animal hace un sonido."); } }
Ejemplo práctico: Clase Hija class Perro extends Animal { public Perro(String nombre, int edad) { super(nombre, edad); } public void moverCola() { System.out.println(nombre + " mueve la cola."); } @Override public void hacerSonido() { System.out.println(nombre + " dice: ¡Guau guau!"); } }
Ventajas de la herencia