eg3-8:
//Birthday.java
package mylib.myclasses;
public class Birthday {
private int year, month, day;//分别表示年月日
public Birthday( ) {
}
public Birthday(int year) {
this();
this.year=year;
}
public Birthday(int year, int month) {
this(year);
this.month=month;
}
public Birthday(int year, int month, int day) {
this(year, month);
this.day=day;
}
public String toString() {
return "出生年月:"+year+"年"+month+"月"+day+"日";
}
public Birthday setYear(int year) {
this.year=year;
return this;
}
public Birthday setMonth(int month) {
this.month=month;
return this;
}
public Birthday setDay(int day) {
this.day=day;
return this;
}
}
eg3-9:
//Test.java
import mylib.myclasses.Birthday;
public class Test {
public static void main(String args[]) {
Birthday obj=new Birthday(1990,11,12);
System.out.println(obj.toString());
String str=obj.setYear(1988).setMonth(8).setDay(28).toString();
System.out.println(str);
}
}
我的软件包就创建在eg3-8下,为什么会不存在呢?高手帮帮忙~~~