public class Test {
public static void main(String[] args) {
Emp[] emps = {
new Emp(1001,"lsm",18,"java","2022.10"),
new Emp(1001,"lsm1",18,"java","2022.10"),
new Emp(1001,"lsm2",18,"java","2022.10")
};

for (Emp e:emps) {
System.out.println(e.toString()); //调用重写得toString方法
}


}
}

class Emp {
private int id;
private String name;
private int age;
private String job;
private String hiredate;

@Override
public String toString() {
return "Emp{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", job='" + job + '\'' +
", hiredate='" + hiredate + '\'' +
'}';
}

public Emp(int id, String name, int age, String job, String hiredate) {
this.id = id;
this.name = name;
this.age = age;
this.job = job;
this.hiredate = hiredate;
}

}
posted on 2022-06-03 14:07  我爱萨菲娜  阅读(27)  评论(0编辑  收藏  举报