java-面向对象中级-习题2-教授信息输出

java-面向对象中级-习题2-教授信息输出,第1张

java-面向对象中级-习题2-教授信息输出 教授信息输出

Homework02 main class

package com.hspedu.homework;

public class Homework02 {
    public static void main(String[] args) {
        Professor a1 = new Professor("林冲",30,"高级职称",30000,1.31,"已婚");
        a1.introduce();
    }

}

Teacher

package com.hspedu.homework;

public class Teacher {
    private String name;
    private int age;
    private String post;
    private double salary;
    //增加一个工资级别
    private double grade;

    public Teacher(String name, int age, String post, double salary, double grade) {
        this.name = name;
        this.age = age;
        this.post = post;
        this.salary = salary;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }

    public void introduce(){
        System.out.println("姓名:" + name +" 年龄:"  + age +  " 职称:" + post +
                " 薪水:" + salary +" 级别:" + grade);
    }
}

Professor

package com.hspedu.homework;

public class Professor extends Teacher{
    //增加一个特有的属性:婚姻状况
    private String marriageStatus;

    public Professor(String name, int age, String post, double salary, double grade, String marriageStatus) {
        super(name, age, post, salary, grade);
        this.marriageStatus = marriageStatus;
    }
a
    @Override
    public void introduce() {
        System.out.println("这是教授的信息:");
        super.introduce();
        System.out.print(marriageStatus);
    }
}

operation result

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5712729.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存