Home > Back-end >  Class inheritance
Class inheritance

Time:04-13

For bosses to have a look at where the wrong man X X

Public class Person {
String id;
String name;
String job;
Public Person (String id, String name, String job) {
This. Id=id;
this.name=name;
This. The job=the job;
}
Public String gettalk () {
Return "id:" + id + "name:" + name + "job:" + job;
}
}
The class Student extends the Person {
Private double money;
Public Student (String id, String name, String job, double money) {
Super (id, name, job);
This. Money=money;
}
Public String gettalk () {
Return "id:" + id + "name:" + name + "job:" + "tuition is:" + money + job;
}
}
The class the Teacher extends the Person {
Public the Teacher (String id, String name, String job, double salary) {
Super (id, name, job);
}
}
The class TestPerson {

Public static void main (String [] args) {
//TODO automatically generated method stub
Student test=new Student (" 2001 ", "zhang", "students", 10000.0);
The Teacher work=new the Teacher (" T001 ", "liu li," "Teacher", 5000.0);
System. The out. Println (test. Gettalk ());
System. The out. Println (work) gettalk ());
}
}
  • Related