Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 1 (13.6 KiB) Viewed 26 times
Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 2 (17.03 KiB) Viewed 26 times
Consider the following implementation of an equals method for comparing a grade object. Is it correct? public class Grade ( public int id; public int score: //[omitted code] public boolean equals(Object o) ( if (this 10) return false; if (o.getClass() 1- this.getClass()) return false; Grade g (Grade) o; return id = g.id && score = g.score;
No - boolean expressions cannot be returned by a return statement so this code won't compile. No - it has identical functionality to the address comparison performed by == Yes it checks if the other class is of the correct type and only then checks the member variables. O Yes - the member variables are primitive types and can be compared directly.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!