public class PersonTest {
public static void main(String[] args) {
Girl girl1=new Girl("朱丽叶",18);
Girl girl2=new Girl("祝英台",20);
Boy b=new Boy("罗密哦",20,girl1,girl2);
//System.out.println("男人只想娶年龄小的");
// if(girl1.compare(girl2)<0) {
// b.marry(girl1);
// }else {
// b.marry(girl2);
// }
// System.out.println("男人只娶年龄小的");
girl1.marry(b);
System.out.println();
girl2.marry(b);
}
}
class Boy{
private String name;
private int age;
Girl girl1=new Girl();
Girl girl2=new Girl();
Boy(){}
Boy(String name,int age){
setName(name);
setAge(age);
}
Boy(String name,int age,Girl girl1,Girl girl2){
this( name, age);
this.girl1=girl1;
this.girl2=girl2;
}
//方法
public void setName(String name) {
this.name=name;
}
public String getName() {
return this.name;
}
public void setAge(int age) {
this.age=age;
}
public int getAge() {
return this.age;
}
publ
罗密哦与朱丽叶----this指针、函数封装
最新推荐文章于 2022-05-09 20:21:07 发布