0

can anyone explain to me every line of this code and what can this code do?

class Animal { String name; Animal(String n) { name = n; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Animal other = (Animal) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } } class Program { public static void main(String[ ] args) { Animal a1 = new Animal("Robby"); Animal a2 = new Animal("Robby"); System.out.println(a1.equals(a2)); } }

7th Apr 2017, 3:53 PM
Hazem Essam
Hazem Essam - avatar
1 Réponse
+ 13
Every line - nope. What are the lines that you don't understand? Maybe you should finish the Java course first - but I think equals and hashCode aren't covered, so https://www.sololearn.com/discuss/277078/?ref=app https://www.sololearn.com/discuss/203939/?ref=app
7th Apr 2017, 6:46 PM
Tashi N
Tashi N - avatar