Junior — Senior
Correct implementation of equals for the Exam class
livecode
Task condition
It is necessary to write an equals method that correctly determines the equality of two Exam class instances. When comparing, all object fields should be considered: identifier, date, and grade.
public class JetbulbInterview {
public static void main(String[] args) {
Exam exam1 = new Exam(1, "04.07.2021", 10);
Exam exam2 = new Exam(1, "04.07.2021", 10);
System.out.println(exam1.equals(exam2));
}
}
class Exam {
long id;
String date;
int mark;
public Exam(long id, String date, int mark) {
this.id = id;
this.date = date;
this.mark = mark;
}
}