Question: 1) Writing/understanding an equals method. a) Complete the equals method in the following class. Two Palette objects are equal if they have the same name

1) Writing/understanding an equals method. a) Complete the equals method in the following class. Two Palette objects are equal if they have the same name and their arrays, colors, have the same elements in the same order.

public class Palette {

private Color[] colors;

private String name;

public Palette(Color[] c, String n) {

colors = c;

name = n;

}

public boolean equals(Object obj) {

if (obj instanceof Palette) {

// Write your code here

} else {

}

}

}

b) If the Palette class were to be inherited, how would you modify the equals method? Explain why?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!