程序代码:
class Person {
private String name;
private int age;
private String address;
private int tel;
public Person() {
}
public Person(String name, int age, String address, int tel) {
this.name = name;
this.age = age;
this.address = address;
this.tel = tel;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getTel() {
return tel;
}
public void setTel(int tel) {
this.tel = tel;
}
@Override
public String toString() {
return "姓名:"+ name + " 年龄:" + age + " 地址:" + address + " 电话:" + tel;
}
}
class Student extends Person {
private String school;
private int id;
public Student() {
super();
}
public Student(String name, int age, String address, int tel,
String school, int id) {
super(name, age, address, tel);
this.school = school;
this.id = id;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return super.toString() + " 学校:" + school + " id:" + id;
}
}
class Teacher extends Person {
private String school;
private int id;
private String career;
public Teacher() {
super();
}
public Teacher(String name, int age, String address, int tel,
String school, int id, String career) {
super(name, age, address, tel);
this.school = school;
this.id = id;
this.career = career;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCareer() {
return career;
}
public void setCareer(String career) {
this.career = career;
}
@Override
public String toString() {
return super.toString() + " 学校:" + school + " id:" + id + " 职位:" + career;
}
}
public class Test {
public static void main(String args[]) {
Student student = new Student("张三",20,"北京",888168,"清华",88);
System.out.println(student);
Teacher teacher = new Teacher("李四",29,"北京",123456,"清华",22,"教师");
System.out.println(teacher);
}
}
帮你修改了代码,按JAVABEAN规范写的,祝你考试成功