SalariedEmployee e1=new SalariedEmployee("zhangsan",7);
e1.setMonthSalary(3000.0);
e1.getYearSalary(month);
System.out.println("员工的姓名是:"+e1.getName()+" 员工生日的月份是:"+e1.getBirthday()+" 员工的职员类型是:"+e1.getClass()+" 员工的工资是:"+e1.getYearSalary(month)+"元");现在想写一个方法就是不是每次都写System.out.println("员工的姓名是:"+e1.getName()+" 员工生日的月份是:"+e1.getBirthday()+" 员工的职员类型是:"+e1.getClass()+" 员工的工资是:"+e1.getYearSalary(month)+"元");这句话而是通过调用一个打印的方法就可以打印员工的信息。
小弟初学java,求指教多谢啦!
e1.setMonthSalary(3000.0);
e1.getYearSalary(month);
System.out.println("员工的姓名是:"+e1.getName()+" 员工生日的月份是:"+e1.getBirthday()+" 员工的职员类型是:"+e1.getClass()+" 员工的工资是:"+e1.getYearSalary(month)+"元");现在想写一个方法就是不是每次都写System.out.println("员工的姓名是:"+e1.getName()+" 员工生日的月份是:"+e1.getBirthday()+" 员工的职员类型是:"+e1.getClass()+" 员工的工资是:"+e1.getYearSalary(month)+"元");这句话而是通过调用一个打印的方法就可以打印员工的信息。
小弟初学java,求指教多谢啦!
return "员工的姓名是:"+e1.getName()+" 员工生日的月份是:"+e1.getBirthday()+" 员工的职员类型是:"+e1.getClass()+" 员工的工资是:"+e1.getYearSalary(month)+"元";
}
以后使用就直接:
System.out.println(e1);
return "员工的姓名是:"+this.getName()+" 员工生日的月份是:"+this.getBirthday()+" 员工的职员类型是:"+this.getClass()+" 员工的工资是:"+this.getYearSalary(month)+"元";
}或者直接写字段名。PS: getClass不行哦,java里class是关键字,不能用class作为变量名。
不知道迭代器行不行,好像可以用迭代器
for(people people :peoples){
system.out.println(people.getName()+...);
}不知道这样行不
这样就可以直接输出对象本身,输出值会按照你在toString里面写的方法输出