logo

Crowdly

Browser

Add to Chrome

What is the output of the following code: import java.util.*; class User {  ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

What is the output of the following code:

import java.util.*;

class User {

    String name;

    User(String name) {

        this.name = name;

    }

    @Override

    public boolean equals(Object o) {

        if (this == o) return true;

        if (!(o instanceof User)) return false;

        User user = (User) o;

        return Objects.equals(name, user.name);

    }

}

public class Test {

    public static void main(String[] args) {

        Set<User> users = new HashSet<>();

        users.add(new User("Alice"));

        users.add(new User("Alice"));

        System.out.println(users.size());

    }

}

0%
0%
3%
97%
More questions like this

Want instant access to all verified answers on learning.devinci.fr?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome