Given the class definition:
class Student{ public Student(int r) { rollNo = r; } int rollNo; }
Choose the correct option based on this code segment:
HashSet<Student> students = new HashSet<>(); students.add(new Student(5)); students.add(new Student(10)); System.out.println(students.contains(new Student(10)));
b)
Since methods equals()
and hashcode()
methods are not overridden in the Student class, the contains()
method will not work as intended and prints false.