public class Man {
int dnaCode;
public boolean equals(Man man) {
return this.dnaCode == man.dnaCode;
}
public static void main(String[] args) {
Man man1 = new Man();
man1.dnaCode = 1111222233;
Man man2 = new Man();
man2.dnaCode = 1111222233;
System.out.println(man1.equals(man2));
}
}
code output is "true"
I am not getting about equals method, how it is implementing?
Can somebody please explain me !!
not getting "dot" operator
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
16 October 2019, 13:44
it is testing that the dna code for the current object is equal (or not equal) to the dna code of the passed in object.
In this code you create two Man objects, Man1 and Man2, then call the equals method from Man1 and pass it the Man2 object. Because both DNA codes are equal you are getting "true". If you changed one of the DNA codes the answer would be false.
0