第1个回答 2017-04-19
public class Test {// 测试类
public static void main(String[] args) throws IOException {
Student s = new Student("zhangsna",12,"nan","默默大学","机械专业");
Teacher t = new Teacher("lili",30,"nv","默默大学","教授","机械");
s.showInfo();
t.showInfo();
}
}
class People{
String name;
int age;
String sex;
public People(String name, int age, String sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}
}
interface JieKou{
final String COUNTRY="china";
public void showInfo();
}
class Student extends People implements JieKou{
private String school;
private String zhuanye;
@Override
public void showInfo() {
System.out.println("姓名:"+name+"\t年龄:"+age+"性别:"+sex+"学校:"+school+",专业:"+zhuanye);
}
public Student(String name, int age, String sex, String school, String zhuanye) {
super(name, age, sex);
this.school = school;
this.zhuanye = zhuanye;
}
}
class Teacher extends People implements JieKou{
private String school;
private String zhicheng;
private String teach;
@Override
public void showInfo() {
System.out.println("姓名:"+name+"\t年龄:"+age+"性别:"+sex+"学校:"+school+",职称:"+zhicheng+",主讲课程:"+teach);
}
public Teacher(String name, int age, String sex, String school, String zhicheng, String teach) {
super(name, age, sex);
this.school = school;
this.zhicheng = zhicheng;
this.teach = teach;
}
}
就这些
第2个回答 2017-04-19
--接口
public interface DisplayPeople {
public final String country="China";
void printInfo(Person p);
}
--抽线类
public abstract class Person implements DisplayPeople{
private String name;
private int age;
private String sex;
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 getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Person(){}
public Person(String name, int age, String sex) {
this();
this.name = name;
this.age = age;
this.sex = sex;
}
}
--Student类
public class Student extends Person implements DisplayPeople{
private String school;
private String profession;
public Student(String school, String profession) {
super();
this.school = school;
this.profession = profession;
}
public Student() {
}
@Override
public void printInfo(Person p) {
// TODO Auto-generated method stub
System.out.println("country:"+DisplayPeople.country+";name:"+p.getName()+";age:"+p.getAge()+";sex:"+p.getSex()+";school:"+this.getSchool()+";profession:"+this.getProfession());
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
}
--Teacher类
public class Teacher extends Person implements DisplayPeople{
private String school;
private String zhicheng;
private String teach;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getZhicheng() {
return zhicheng;
}
public void setZhicheng(String zhicheng) {
this.zhicheng = zhicheng;
}
public String getTeach() {
return teach;
}
public void setTeach(String teach) {
this.teach = teach;
}
@Override
public void printInfo(Person p) {
System.out.println("country:"+DisplayPeople.country+";name:"+p.getName()+";age:"+p.getAge()+";sex:"+p.getSex()+";school:"+this.getSchool()+";zhicheng:"+this.getZhicheng()+";teach:"+this.getTeach());
}
}
--测试类
public class Client {
public static void main(String[] args) {
Student student=new Student();
student.setAge(20);
student.setName("John");
student.setSex("Male");
student.setProfession("couputer");
student.setSchool("Beijingdaxue");
Person p=student;
p.printInfo(p);
Teacher tea=new Teacher();
tea.setAge(25);
tea.setName("Mary");
tea.setSex("Female");
tea.setTeach("English");
tea.setSchool("Beijingdaxue");
Person p1=tea;
p.printInfo(p1);
}
}本回答被提问者和网友采纳