1 PackageOne ;2 ImportJava.util.*;3 Importjava.text.*;4 classperson{5 PublicString name;6 PublicDate birthday;7 PublicString sex, province,city;8 Private Static intCount=0;9 PublicPerson (String name,date birthday,Ten String sex,string province,string City) { One This. name=name; A This. birthday=birthday; - This. sex=sex; - This. province=Province; the This. city=City ; - } - PublicPerson (String name,date birthday) { - This(Name,birthday, "", "", ""); + } - PublicPerson () { + This("",NULL); A } at PublicPerson (person p) { - This. Set (p.name,p.birthday,p.sex,p.province,p.city); - } - - Public voidFinalize () { -System.out.println ("Release object (" + This. toString () + ")"); inperson.count--; - } to PublicString toString () { + returnName+ "," + (birthday==NULL? "": birthday.tostring ()) + "," + -(sex==NULL? "": Sex) + "," + (province==NULL? "":p rovince) + the(city==NULL?"": City); * } $ Public voidSet (String name,date birthday,string sex,string Province,Panax Notoginseng String City) { - This. name=name==NULL?"": Name; the This. sex=sex==NULL?"": Sex; + This. province=province==NULL?"":p rovince; A This. city=city==NULL?"": City; theCalendar calendar=NewGregorianCalendar (0000,00,00,0,0,0); +Date date=calendar.gettime (); - This. birthday=birthday==NULL?Date:birthday; $ } $ Public Static voidHowmany () { -System.out.println (person.count+ "Person Object"); - } the } - Wuyi Public classStudentextendsPerson { the PublicString Department; - PublicString number; Wu PublicString speciality; - Public Booleanmember; About Private Static intCount=0; $ PublicStudent (String name,date birthday,string sex,string Province, - String city,string number,string department,string speciality, - Booleanmember) { - Super. Set (name, birthday, sex, province, city); A This. Set (Number,department,speciality,member); +count++; the } - Public voidSet (String number,string department,string specilality, $ Booleanmember) { the This. number=number==NULL?"": number; the This. department=department==NULL?"":d epartment; the This. speciality=speciality==NULL?"": Speciality; the This. member=member; - } in Public voidFinalize () { the Super. Finalize (); thestudent.count--; About } the PublicStudent (person p,string number,string department,string speciality, the Booleanmember) { the This(P.name,p.birthday,p.sex,p.province,p.city,number,department, +Speciality,member);//There is no point behind this - } the PublicStudent (Student s) {Bayi This(S.name,s.birthday,s.sex,s.province,s.city,s.number, the s.department,s.speciality,s.member); the } - Public Static voidHowmany () { - Person.howmany (); theSystem.out.println (student.count+ "Student objects"); the } the PublicString toString () { the return Super. toString () + "," +department+ "," +speciality+ "," +number+ -"," + (member? ") Member ":"); the } the Public Static voidMain (string[] args) { the //TODO auto-generated Method Stub94 the } the the}
Java3-class Student