Users as strings

Report a typo

You are given a class named User. It has three string fields: login, firstName, lastName. Override the method toString() in the class to return string representations of users.

The overridden method must return a string including all field-value pairs separated by commas.

Here is an example: "login=javagod,firstName=James,lastName=Gosling".

Sample Input 1:

javagod James Gosling

Sample Output 1:

login=javagod,firstName=James,lastName=Gosling
Write a program in Java 17
class User {

private String login;
private String firstName;
private String lastName;

public User(String login, String firstName, String lastName) {
this.login = login;
this.firstName = firstName;
this.lastName = lastName;
}
}
___

Create a free account to access the full topic