第一步定义了一个接口:
package mypack;public interface lStudent {
public void doLession();
}第二步定义了一个实现类,实现类下有1个Birthday类
package mypack;public class PartStudent implements lStudent{ private String name1;
private String name2;
private Birthday birthday;
// public String getName() {
// return name;
// }
// public void setName(String name) {
// this.name = name;
// }
public PartStudent(String name1,String name2)
{
this.name1 =name1;
this.name2 =name2;
}
public void doLession() {
System.out.println("出生于"+birthday+name1+"和"+birthday+name2+"在一起生活");
[color=#FF0000问题如下:如何给不同的变量生成不同的年月日][/color]

}
public Birthday getBirthday() {
return birthday;
}
public void setBirthday(Birthday birthday) {
this.birthday = birthday;
}

}第三步生成了Birthday类
package mypack;public class Birthday {
private int year;
private int month;
private int date;
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}第四步:建立的bean-xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id ="birthday" class="mypack.Birthday">
<property name="year">
<value>1984</value>
</property>
<property name="month">
<value>1</value>
</property>
<property name="date">
<value>5</value>
</property>
</bean><bean id="stu" class="mypack.PartStudent">
<!-- property name="name">
<value>小琳</value>
</property> -->
<property name="birthday" ref="birthday"></property>
<constructor-arg index="0">
<value>小琳</value>
</constructor-arg>
<constructor-arg index="1">
<value>小新</value>
</constructor-arg>
</bean></beans>第五步实现类
package mypack;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;public class Test {
public static void main(String[] args)
{
//从类路径上读取配置文件bean.xml
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
  //通过id="stu" 找到类PartStudent的实例
lStudent is =(lStudent)context.getBean("stu");
is.doLession();
}
//输出出生于1984-1-5小琳和1984-1-5小新在一起生活。问题是如何给第二个人添加生日??
}