用java定义一个person类,属性有姓名,性别,年龄,住址,工作单位,工资
时间: 2023-05-18 13:05:26 浏览: 150
java person类
public class Person {
private String name;
private String gender;
private int age;
private String address;
private String company;
private double salary;
public Person(String name, String gender, int age, String address, String company, double salary) {
this.name = name;
this.gender = gender;
this.age = age;
this.address = address;
this.company = company;
this.salary = salary;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
public String getCompany() {
return company;
}
public double getSalary() {
return salary;
}
public void setName(String name) {
this.name = name;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setAge(int age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
public void setCompany(String company) {
this.company = company;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", gender='" + gender + '\'' +
", age=" + age +
", address='" + address + '\'' +
", company='" + company + '\'' +
", salary=" + salary +
'}';
}
}
阅读全文