Public static void main (strinargs []) {
Student s 1 = freshman ();
Student s2 = freshman ("Zhang San",1989,7,7);
Student s3 = freshman ("Zhang San", new my date ());
Student s4 = freshman ("Zhang San", new my date (April, 2009,1));
s 1 . print();
S2 . print();
S3 . print();
S4 . print();
}
}
Category My Date {
Private int year;
Private int month;
Private int day;
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;
}
public int getDay() {
Return date;
}
public void setDay(int day) {
this.day = day
}
public MyDate(){
this . year = 1999;
this . month = 1;
this . day = 1;
}
Public MyDate (integer year, integer month, integer day) {
this.year = year
This.month = month;
this.day = day
}
}
Class students {
Private string name;
My personal date birthday;
Public string getName() {
Returns the name;
}
Public void setName {
this.name = name
}
public MyDate getBirthday() {
Return to your birthday;
}
Public void setBirthday {
This.birthday = birthday;
}
Public students () {
this.name = " default
this . birthday = new MyDate();
}
Public Student (string name, integer year, integer month, integer day) (
this.name = name
This.birthday = new MyDate (year, month, day);
}
Public student (string name, my birthday) {
super();
this.name = name
This.birthday = birthday;
}
Public void printing () {
system . out . println(" name = "+name+" \ nbirthday = "+birthday . getyear()+","+
birthday.getMonth() +" "+birthday . getday());
}
}
Results:
Name = Default
Birthday = 1999. 1. 1
Name = Zhang San
Birthday = 1989.7.7
Name = Zhang San
Birthday = 1999. 1. 1
Name = Zhang San
Birthday = April 2009.1