Java声明一个person类,私有化属性name和age并将字段封装起来
时间: 2024-06-06 10:10:51 浏览: 234
类来封装对象的属性和功能
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
阅读全文