实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。

1Person类中的属性有:姓名nameString类型),地址addressString类型),

电话号码telphoneString类型)和电子邮件地址emailString类型)

2Employee类中的属性有:办公室officeString类型),工资wagedouble

类型),受雇日期hiredateString类型)

3Faculty类中的属性有:学位degreeString类型),级别levelString类型)

4Staff类中的属性有:职务称号dutyString类型)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package zuoye;
 
public class Person {
    //属性
    public String name;//姓名
    public String address;//地址
    public String telphone;//电话
    public String email;//邮箱
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getTelphone() {
        return telphone;
    }
    public void setTelphone(String telphone) {
        this.telphone = telphone;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
     
     
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package zuoye;
 
public class Employee extends Person{
    public String office;//办公室
    public double wage;//工资
    public String hiredate;//受雇日期
    public String getOffice() {
        return office;
    }
    public void setOffice(String office) {
        this.office = office;
    }
    public double getWage() {
        return wage;
    }
    public void setWage(double wage) {
        this.wage = wage;
    }
    public String getHiredate() {
        return hiredate;
    }
    public void setHiredate(String hiredate) {
        this.hiredate = hiredate;
    }
     
     
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package zuoye;
 
public class Faculty extends Employee {
    public String degree;//学位
    public String level;//级别
     
    public String getDegree() {
        return degree;
    }
    public void setDegree(String degree) {
        this.degree = degree;
    }
    public String getLevel() {
        return level;
    }
    public void setLevel(String level) {
        this.level = level;
    }
     
     
     
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package zuoye;
 
public class Staff extends Employee{
 
    public String duty;
 
    public String getDuty() {
        return duty;
    }
 
    public void setDuty(String duty) {
        this.duty = duty;
    }
     
     
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package zuoye;
 
public class Ceshi_person {
 
    public static void main(String[] args) {
    //测试
        Person p=new Person();
        p.setName("张三");
        p.setAddress("x省x市x区123号");
        p.setEmail("510652434@qq,com");
        p.setTelphone("189xxxx6492");
        System.out.println("姓名是:"+p.getName()+"地址是:"+p.getAddress()+"电话:"+p.getTelphone()+"邮箱:"+p.getEmail());
         
        Employee e=new Employee();
        e.setOffice("A座407");
        e.setWage(5000.0);
        e.setHiredate("16.08.16");
        System.out.println("信息是:姓名是:"+p.getName()+"地址是:"+p.getAddress()+"电话:"+p.getTelphone()+"邮箱:"+p.getEmail()+"办公室:"+e.getOffice());
    }
 
}

  

 

posted @   琢磨先生  阅读(5271)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 《HelloGitHub》第 106 期
· 数据库服务器 SQL Server 版本升级公告
· C#/.NET/.NET Core技术前沿周刊 | 第 23 期(2025年1.20-1.26)
AmazingCounters.com
点击右上角即可分享
微信分享提示