日期:2014-05-20 浏览次数:20802 次
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
abstract class Citizen{
private String identityCardNumber;
private String name;
private char gender;
private String birthPlace;
private Date birthday;
public String getIdentityCardNumber() {
return identityCardNumber;
}
public void setIdentityCardNumber(String identityCardNumber) {
this.identityCardNumber = identityCardNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public String getBirthPlace() {
return birthPlace;
}
public void setBirthPlace(String birthPlace) {
this.birthPlace = birthPlace;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
Citizen(String identityCardNumber, String name, char gender){
this.setIdentityCardNumber(identityCardNumber);
this.setName(name);
this.setGender(gender);
}
Citizen(String identityCardNumber, String name, char gender, String birthplace, Date birthday){
this.setIdentityCardNumber(identityCardNumber);
this.setName(name);
this.setGender(gender);
this.setBirthPlace(birthplace);
this.setBirthday(birthday);
}
Citizen(){
System.out.println("默认构造方法。");
}
void printInfo( ){
System.out.println("该对象的居民身份属性如下:");
System.out.println("身份证号:"+this.getIdentityCardNumber());
System.out.println("姓名:"+this.getName());
System.out.println("性别:"+this.getGender());
System.out.println("籍贯:"+this.getBirthPlace());
System.out.println("生日:"+this.getBirthday());
}
abstract void work( );
}
class Student extends Citizen{
private String studentNumber;
private String major;
private String collegeName;
public String getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String collegeName) {
this.collegeName = collegeName;
}
Student(String studentNumber,String major,String collegeName){
this.setStudentNumber(studentNumber);
this.setMajor(major);
this.setCollegeName(collegeName);
}
void printInfo( ){
System.out.println("该对象的学生身份属性如下:");
System.out.println("学号:"+this.getStudentNumber());
System.out.println("专业:"+this.getMajor());
System.out.println("学校:"+this.getCollegeName());
super.printInfo();
}
void work(){
System.out.println("学生的工作是:学习!");
}
}
class Worker extends Citizen{
private String typeOfWork;
public String getTypeOfWork() {
return typeOfWork;
}
public void setTypeOfWork(String typeOfWork) {
this.typeOfWork = typeOfWork;
}
Worker(String typeOfWork){
this.setTypeOfWork(typeOfWork);
}
void printInfo( ){
System.out.println("该对象的工人身份属性如下:");
System.out.println("工种:"+this.getTypeOfWork());