Question: URGENT, PLEASE ADD NEEDED CODE TO THE BOLD SECTION BELOW. Complete the following equals(..) method which is overriding the equals method of the Class Object,
URGENT, PLEASE ADD NEEDED CODE TO THE BOLD SECTION BELOW.
Complete the following equals(..) method which is overriding the equals method of the Class Object, where it indicates whether some other object contains the same values on all of the fields. For example, the two instance c1 and c2 are different instance, but have same values of fields.
class Car { String color; int speed; Car(String color, int speed) { this.color = color; this.speed = speed; } public boolean equals(Object otherObject) { if(otherObject == null) return false; if (getClass() != otherObject.getClass()) return false; Car otherCar = (Car)otherObject; //write codes here //remember this method returns a boolean type variable } public static void main(String[] args) { Car c1 = new Car("Red", 1); Car c2 = new Car("Red", 1); System.out.println(c1.equals(c2));//expect to display "true" } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
