Page 1 of 1

Consider the following implementation of an equals method for comparing a grade object. Is it correct? public class Grad

Posted: Mon Jun 06, 2022 6:26 pm
by answerhappygod
Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 1
Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 1 (13.6 KiB) Viewed 28 times
Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 2
Consider The Following Implementation Of An Equals Method For Comparing A Grade Object Is It Correct Public Class Grad 2 (17.03 KiB) Viewed 28 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.