Question 12
Consider the code given below that checks whether two Persons are the same. Method equals is overridden to compare two Person objects as follows. If two Persons have the same name and age, then they are the same. Based on the given information, answer the question that follows.
class Person { private String name; private int age;
// Constructor to initialize instance variables
public String toString() { return name + " (" + age + " years old)"; } public boolean equals(Object obj) { //CODE BLOCK }}public class TestPerson { public static void main(String[] args) { Person person1 = new Person("Alice", 25); Person person2 = new Person("Alice", 25); if (person1.equals(person2)){ System.out.println(person1 + " and " + person2 + " are the same"); } else{ System.out.println(person1 + " and " + person2 + " are different"); } }}Choose the correct option to fill in place of CODE BLOCK so that the output is:
Alice (25 years old) and Alice (25 years old) are the same