用java继承的方法写员工类,程序员类,项目经理类,按图片内容编写程序,
时间: 2023-09-30 22:08:37 浏览: 190
很抱歉,我无法看到你所提到的图片内容。但是,我可以给你提供一个简单的示例,演示如何使用Java继承来创建员工类,程序员类和项目经理类。
首先,我们可以定义一个基本的员工类,包含员工的姓名和工资属性:
```java
public class Employee {
private String name;
private double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
```
接下来,我们可以创建一个程序员类,继承自员工类,并添加一个语言属性:
```java
public class Programmer extends Employee {
private String language;
public Programmer(String name, double salary, String language) {
super(name, salary);
this.language = language;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
}
```
最后,我们可以创建一个项目经理类,继承自员工类,并添加一个团队属性:
```java
public class ProjectManager extends Employee {
private String team;
public ProjectManager(String name, double salary, String team) {
super(name, salary);
this.team = team;
}
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
}
```
这样,我们就创建了一个简单的继承体系,可以创建员工、程序员和项目经理对象,并访问它们的属性和方法。
阅读全文