黑马程序员技术交流社区
标题:
看下有什么问题,
[打印本页]
作者:
1642059279
时间:
2015-1-12 08:32
标题:
看下有什么问题,
class Employee{
private String name;
private int age;
private float salary;
private Manager m;
public Employee(){
this.name=null;
this.age=0;
this.salary=0.0f;
this.m=null;
}
public Employee(String name,int age,float salary){
this.setName(name);
this.setAge(age);
this.setSalary(salary);
}
public String say(){
return "姓名:"+this.getName()+" 年龄:"+this.getAge()+" 薪水:"+this.getSalary();
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return this.age;
}
public void setSalary(float salary){
this.salary=salary;
}
public float getSalary(){
return this.salary;
}
public void setM(Manager m){
this.m=m;
}
public Manager getM(){
return this.m;
}
}
class Manager extends Employee{
private int num;
public Manager(){
}
public Manager(String name,int age,float salary,int num){
super(name,age,salary);
this.setNum(num);
}
public String say(){
return super.say()+" 管理人员数:"+this.getNum();
}
public void setNum(int num){
this.num=num;
}
public int getNum(){
return this.num;
}
}
class EmployeeDemo
{
public static void main(String[] args){
Employee e=new Employee("张三",25,5200);
e.say();
Manager m=new Manager("李四",35,12000,30);
m.say();
System.out.println(e.say());
System.out.println(m.say());
}
}
作者:
李增宽
时间:
2015-1-12 21:47
你这写的有点乱啊,你的无参构造方法里面的代码没有意义啊,而且直接this.成员变量就可以了,不用再调用方法了,下面看不下去了.........
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2