代码:
public class LL {public static void main(String[] args) {
Teacher t=new Teacher("Mike",32,"前端页面",20000);Professor P= new Professor("Jack",58,"嵌入式开发",20000);pro p= new pro("Bob",34,"Java开发工程师",20000);lecturer l= new lecturer("Lili",28,"软件工程师",20000);System.out.println(P.introduce());System.out.println(t.introduce());System.out.println(p.introduce());System.out.println(l.introduce());}
}
class Teacher{String name;int age;String post;double salary;public Teacher(String name, int age, String post, double salary) {this.name = name;this.age = age;this.post = post;this.salary = salary;}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 getPost() {return post;}public void setPost(String post) {this.post = post;}public double getSalary() {return salary;}public void setSalary(double salary) {this.salary = salary;}@Overridepublic String toString() {return "Teacher{" +"name='" + name + '\'' +", age=" + age +", post='" + post + '\'' +", salary=" + salary +'}';}public String introduce(){return "姓名为:"+getName()+", 年龄为:"+getAge()+", 职位为:"+getPost()+", 工资为:"+getSalary();}
}
class Professor extends Teacher{public Professor(String name, int age, String post, double salary) {super(name, age, post, salary);}public String introduce(){return "教授姓名为:"+getName()+", 年龄为:"+getAge()+", 职位为:"+getPost()+", 工资为:"+getSalary()*1.3;}
}
class pro extends Teacher {public pro(String name, int age, String post, double salary) {super(name, age, post, salary);}public String introduce() {return "副教授姓名为:" + getName() + ", 年龄为:" + getAge() + ", 职位为:" + getPost() + ", 工资为:" + getSalary() * 1.2;}
}class lecturer extends Teacher {public lecturer(String name, int age, String post, double salary) {super(name, age, post, salary);}public String introduce() {return "讲师姓名为:" + getName() + ", 年龄为:" + getAge() + ", 职位为:" + getPost() + ", 工资为:" + getSalary() * 1.1;}}
运行结果: