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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 26 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 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!
Post Reply