概念
this调用构造器
案例
package lesson.l11_oop2;
/**
* Illustration
*
* @author DengQing
* @version 1.0
* @datetime 2022/7/3 17:11
* @function
*/
public class Girl {
private String name;
private Integer age;
public Girl() {
}
public Girl(String name, Integer age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public void marry(Boy boy) {
System.out.println("marry" + boy.getName());
boy.marry(this);
}
public int compare(Girl girl) {
System.out.println("compare" + girl.getName());
/* if (this.getAge() > girl.getAge()) {
return 1;
} else if (this.getAge().equals(girl.getAge())) {
return 0;
} else {
return -1;
}*/
return this.getAge()- girl.getAge();
}
}