package sj;
public class People {
protected static String name;//姓名
protected static String sex;//性别
protected static int age;//年龄
public void eat(){//吃
System.out.println("我是人,我爱吃饭!");
}
public void speak(){//说话
System.out.println("我是人,我爱说话!");
}
public People(String name,String sex,int age) {//初始化共有属性
this.name=name;
this.sex=sex;
this.age=age;
}
}
package sj;
public class Employee extends People {
protected long EmpNo;//工号
public void eat(){
System.out.println("我是员工,我爱吃饭");
}
public void speak(){
System.out.println("我是员工,我爱说话");
}
public void work(){
System.out.println("我是员工,我的工作内容很简单!");
}
public Employee(String name, String sex, int age, long EmpNo){//构造方法
super(name,sex,age);//重定义父类成员变量
this.EmpNo = EmpNo;
}
}
package sj;
public class test {
public static void main(String[] args){
Employee employee = new Employee("张三","男",18,13000000);
System.out.println("这是一名员工:");
System.out.println("姓名:"+employee.name);System.out.println("性别:"+employee.sex);System.out.println("年龄:"+employee.age);
System.out.println("工号:"+employee.EmpNo);
employee.eat();
employee.speak();
employee.work();
System.out.println();
People people = new People("丽丝","女",16);
System.out.println("这是一个普通的人:");
System.out.println("姓名:"+people.name);
System.out.println("性别:"+people.sex);
System.out.println("年龄:"+people.age);
people.eat();
people.speak();
}
}
标签:java,System,sex,employee,实训,println,public,out
From: https://blog.csdn.net/2301_77631967/article/details/137153508