equals on a class and on a record
Predict the outputMedium-HardJava only
class PointClass {
int x, y;
PointClass(int x, int y) {
this.x = x;
this.y = y;
}
}
record PointRecord(int x, int y) {}
public class Main {
public static void main(String[] args) {
PointClass a = new PointClass(1, 2);
PointClass b = new PointClass(1, 2);
System.out.println(a.equals(b));
PointRecord c = new PointRecord(1, 2);
PointRecord d = new PointRecord(1, 2);
System.out.println(c.equals(d));
System.out.println(c == d);
System.out.println(c);
}
}
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.