Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members

Multiple constructors

Time

Report a typo

Here's a class named Time with three fields: hours, minutes and seconds.

Add three constructors to the class:

  • The first one takes only hours and initializes this field;
  • The second one takes hours and minutes and initializes the corresponding fields;
  • The third one takes hours, minutes and seconds and initializes all fields.

Do not make the fields and constructors private.

Write a program in Java 17
class Time {

int hours;
int minutes;
int seconds;
}
___

Create a free account to access the full topic