java编写一个employee 类
时间: 2023-04-27 10:02:29 浏览: 129
好的,下面是一个简单的Java Employee类的示例:
```
public class Employee {
private String name;
private int age;
private double salary;
public Employee(String name, int age, double salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public double getSalary() {
return salary;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void printEmployee() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Salary: " + salary);
}
}
```
这个Employee类有三个私有属性:name、age和salary,以及一个构造函数和一些getter和setter方法。它还有一个printEmployee方法,用于打印Employee对象的属性。您可以根据需要进行修改和扩展。
阅读全文