package javac;
class Dept{
private String name;
private String num;
private Emp[] emps;
private Emp mgr;
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public Dept(String name,String num){
this.name=name;
this.num=num;
}
public String getDeptInfo(){
return this.name+this.num;
}
public Emp[] getEmps() {
return emps;
}
public void setEmps(Emp []emps) {
this.emps = emps;
}
public Emp getMgr() {
return mgr;
}
public void setMgr(Emp mgr) {
this.mgr = mgr;
}
}
class Emp{
private int id;
private String name;
private int age;
private String post;
private Dept dept;
private Emp mgr;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 Emp(String name,int id,int age,String post){
this.name=name;
this.age=age;
this.id=id;
this.post=post;
}
public String getEmpInfo(){
return name+id+age+post;
}
public Dept getDept() {
return dept;
}
public void setDept(Dept dept) {
this.dept = dept;
}
public Emp getMgr() {
return mgr;
}
public void setMgr(Emp mgr) {
this.mgr = mgr;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
}
public class biao {
public static void main(String args[]){
Emp ea=new Emp("zhangsan",001,10,"员工");
Emp eb=new Emp("lisi",002,10,"经理");
Dept dept=new Dept("bmw","001");
ea.setDept(dept);
eb.setDept(dept);
ea.setMgr(eb);
dept.setMgr(eb);
dept.setEmps(new Emp[]{
ea,eb
});
System.out.println(dept.getDeptInfo());
for(int x=0;x<dept.getEmps().length;x++){
{
System.out.println("\t"+dept.getEmps()[x].getEmpInfo());
if(dept.getEmps()[x].getMgr()!=null)
System.out.println("\t\t"+dept.getEmps()[x].getMgr().getEmpInfo());
}
}
System.out.println("*****************************");
System.out.println(dept.getMgr().getEmpInfo());
System.out.println("*****************************");
System.out.println(ea.getDept().getDeptInfo());
System.out.println(ea.getMgr().getEmpInfo());
}
}
简单类(进阶)
最新推荐文章于 2024-05-12 01:57:16 发布