Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members

Multiple constructors

Phone

Report a typo

Below is a class named Phone. It has four fields: ownerName, countryCode, cityCode and number.

Add two constructors to the class:

  • the first one takes ownerName and number and initializes the corresponding fields;
  • the second one takes ownerName, countryCode, cityCode, number and initializes all fields.

Do not make the fields and constructors private.

Write a program in Java 17
class Phone {

String ownerName;
String countryCode;
String cityCode;
String number;
}
___

Create a free account to access the full topic