
上面的解题代码请求请求,不是很会,想找一个正确的解题思路进行模仿的思考
给个例子做参考,文件要保存为MyTest.java,或者修改代码里的MyTest为你的文件名:
class Staff{
String name;
int age;
String sex;
public Staff(String name, int age, String sex){
this.name =name;
this.age = age;
this.sex = 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 void showInfo(){
System.out.println("姓名:"+this.name+" 年龄:"+this.age+" 性别:"+this.sex);
}
}
class Manager extends Staff {
String post;
int salary;
public Manager(String name, int age, String sex, String post, int salary) {
super(name, age, sex);
this.post = post;
this.salary = salary;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public void showInfo(){
System.out.println("姓名:"+this.name+" 年龄:"+this.age+" 性别:"+this.sex+" 职务:"+this.post+" 年薪:"+this.salary);
}
}
class Employee extends Staff {
String department;
int monthly;
public Employee(String name, int age, String sex, String department, int monthly) {
super(name, age, sex);
this.department = department;
this.monthly = monthly;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getMonthly() {
return monthly;
}
public void setMonthly(int monthly) {
this.monthly = monthly;
}
public void showInfo(){
System.out.println("姓名:"+this.name+" 年龄:"+this.age+" 性别:"+this.sex+" 部门:"+this.department+" 月薪:"+this.monthly);
}
}
public class MyTest{
public static void main(String[] args) {
Manager manager = new Manager("张三", 38, "男", "总经理", 3000000);
Employee employee = new Employee("李四", 28, "女", "研发部", 5300);
manager.showInfo();
employee.showInfo();
}
}
