The equality of users

Report a typo

Given a class named User that represents users on a web site. The class overrides the equals method using the id field.

class User {
    private long id;
    private String name;
    
    // constructor, getters and setters
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return false;
        }
        
        if (obj != null && !(obj instanceof User)) {
            return false;
        }

        User user = (User) obj;
        
        return id == user.id;
    }

    // overridden hashCode() method
}

Select all restrictions that are not satisfied.

Select one or more options from the list
___

Create a free account to access the full topic