代码拉取完成,页面将自动刷新
package basic.c08_oop;
/*
Clase 7 - Polimorfismo, abstracción y composición (21/05/2025)
Vídeo: https://www.twitch.tv/videos/2464789369
*/
public class Polymorphism {
public static void main(String[] args) {
// Polimorfismo
// - Polimorfismo por herencia (sobrescritura)
var animal = new Animal();
animal.sound();
var dog = new Dog();
dog.sound();
// - Polimorfismo por sobrecarga (sobrecarga de métodos)
var calculator = new Calculator();
System.out.println(calculator.sum(3, 5));
System.out.println(calculator.sum(3.2, 5.4));
}
// - Polimorfismo por herencia (sobrescritura)
public static class Animal {
public void sound() {
System.out.println("Algún sonido");
}
}
public static class Dog extends Animal {
@Override
public void sound() {
System.out.println("Guau");
}
}
// - Polimorfismo por sobrecarga (sobrecarga de métodos)
public static class Calculator {
public int sum(int a, int b) {
return a + b;
}
public int sum(int a, int b, int c) {
return a + b + c;
}
public double sum(double a, double b) {
return a + b;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。