设计Teacher类,继承Person类,用java编写。各位高手帮忙。越简单越好。
2个回答
展开全部
父类Person要用proteced才能让子类继承。
public class Teacher {
private int teachId;
private String school;
public Teacher(int teacherId) {
super();
this.teachId = teacherId;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public int getTeachId() {
return teachId;
}
public void setTeachId(int teachId) {
this.teachId = teachId;
}
}
class Person{
protected String name;
protected char sex;
protected String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
protected char getSex() {
return sex;
}
protected void setSex(char sex) {
this.sex = sex;
}
}
public class Teacher {
private int teachId;
private String school;
public Teacher(int teacherId) {
super();
this.teachId = teacherId;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public int getTeachId() {
return teachId;
}
public void setTeachId(int teachId) {
this.teachId = teachId;
}
}
class Person{
protected String name;
protected char sex;
protected String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
protected char getSex() {
return sex;
}
protected void setSex(char sex) {
this.sex = sex;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Person {
protected String name;
protected String gender;
protected int age;
public Person(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Teacher extends Person{
private int salary;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
protected String name;
protected String gender;
protected int age;
public Person(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Teacher extends Person{
private int salary;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询