1、父类
package com.wyq.study;
public class Employer {
private String name = "sdf";
int age;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
// public void setAge(int age){
// this.age = age;
// }
// public int getAge(){
// return age;
// }
public Employer(){
super();
System.out.println("无参构造"+this.name+"\t"+this.age);
}
public Employer(String name,int age){
super();
this.name = name;
this.age = age;
System.out.println("employer的带参构造"+this.name+"\t"+age);
}
}
2、子类
package com.wyq.study;
public class Employee extends Employer{
private String department;
public void setDepartment(String department){
this.department = department;
}
public String getDepartment(){
return department;
}
public Employee(){
super();
System.out.println("这里是子类的无参构造");
}
public Employee(String name,int age,String department){
super(name,age);
this.department = department;
}
public void show(){
System.out.println(super.getName()+"\t"+super.age);
}
}
3、测试类
package com.wyq.study;
public class TestEmp {
public static void main(String[] args) {
Employee e = new Employee("李四",12,"财务部");
e.show();
System.out.println(e+"\t"+e.age+"\t"+e.getName()+"\t"+e.getDepartment());
}
}