2 Star 0 Fork 0

热门极速下载/hello-java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Person.java 869 Bytes
一键复制 编辑 原始数据 按行查看 历史
Brais Moure 提交于 1个月前 . Clase 6 | 14/05/2025
package basic.c08_oop;
/*
Clase 6 - Clases, encapsulamiento y herencia (14/05/2025)
Vídeo: https://www.twitch.tv/videos/2459212698
*/
public class Person {
// Atributos
protected String name;
private int age;
final private String id;
// Constructor
public Person(String name, int age, String id) {
this.name = name;
this.setAge(age);
this.id = id;
}
// Métodos
public void sayHello() {
System.out.println("Hola, soy " + name + ", tengo " + age + " años, y mi id es " + id + ".");
}
// Getter
public int getAge() {
return age;
}
public String getId() {
return id;
}
// Setter
public void setAge(int age) {
if (age > 0) {
this.age = age;
} else {
System.out.println("Edad no válida");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trending/hello-java.git
git@gitee.com:mirrors_trending/hello-java.git
mirrors_trending
hello-java
hello-java
main

搜索帮助