package bbb;
public class Person {
private String name;
private int age;
public Person(){
}
public Person(String name){
this.name = name;
}
public Person(int age){
this.age = age;
}
public Person(String name,int age){
this.name = name;
this.age = age;
}
public String getName(String name){
return name;
}
public void setName(String name){
this.name = name;
}
public int getage(int age){
return age;
}
public void setAge(int age){
if(age<0){
this.age=0;
}else{
this.age = age;
}
}
public void printMessage(){
System.out.println("name = "+name+",age = "+age);
}
public void addAge(){
age++;
}
}
package bbb;
public class TestPerson{
public static void main(String[] args) {
Person p1 = new Person("蔡旭坤",30);
p1.addAge();
p1.printMessage();
Person p2 = new Person("王俊凯",20);
p2.addAge();
p2.printMessage();
Person p3 = new Person();
}
}