Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members

Multiple constructors

Employee

Report a typo

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.

Write a program in Java 17
class Employee {

String name;
int salary;
String address;
}
___

Create a free account to access the full topic