Multiple constructors Employee

Here's a class named Employee with three fields: name, salary, address.

Add three constructors to the class:

the first one is the no-argument constructor, it should initialize string fields with the value "unknown", the salary is 0;
the second one takes name and salary, and then initializes the corresponding fields, the address is "unknown";
the third one takes name, salary, address and initializes all fields.
Do not make the fields and constructors private.

class Employee {

    String name;
    int salary;
    String address;

    public Employee() {
        this("unknown", 0);
    }

    public Employee(String name, int salary) {
        this(name, salary, "unknown");
    }

    public Employee(String name, int salary, String address) {
        this.name = name;
        this.salary = salary;
        this.address = address;
    }
}
posted @ 2020-09-09 17:39  longlong6296  阅读(122)  评论(0)    收藏  举报