下面的代码如何才能编译成功??求学长、老师们,在线急等!!关联母亲类和女儿类之后是不是也要set和get呢????
/**
对象的一对一关系
*/
public class OneToOneDemo{
public static void main(String[] args){
Mother m = new Mother("张妈妈",'女');
Daugther d = new Daugther("程蒙蒙",19);
下面这里如何设置她俩之间的关系呢?并且打印输出
}
}
/**
一个孩子只有一个亲生母亲(一对一关系)
*/
class Mother{ //母亲类
private String name;
private char sex;
private Daugther daugther; //关联女儿类
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public void setSex(char s){
sex = s;
}
public char getSex(){
return sex;
}
public Mother(){}
public Mother(String name,char sex){
this.name = name;
this.sex = sex;
}
}
class Daugther{ //女儿类
private String name;
private int age;
private Mother Mother; //关联母亲类
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public void setAge(int a){
age = a;
}
public int getAge(){
return age;
}
public Daugther(){}
public Daugther(String name,int age){
this.name = name;
this.age = age;
}