-2
Public Class ClassATest {
public static void main(String a[]) {
ClassA a = new ClassA(10);
ClassA b = new ClassA(10);
if(a.equals(b)) {
 //do something.
}
}
}
Public ClassA {
private int someValue;
ClassA(int val) {
someValue = vall
}
// Overriding equals method as..

public boolean equals(object o) {
if((o instance of Object) && (((ClassA)o).getSomeMethod() == **this**.someValue) {
return true;
}
}

Question is.. What is this referring to? Assuming implementation a.equals(b) as -- b instance of Object && b.getSomeMethod == this.someValue; Can you please explain.. whis 'this' refer to here ? this.someValue means what?? /

  • 4
    possible duplicate of [What is the meaning of "this" in Java?](http://stackoverflow.com/questions/3728062/what-is-the-meaning-of-this-in-java) – Emil Laine Apr 04 '15 at 14:48

1 Answers1

0

It means the instance of the class that the code is in, in your example it would be an instance of the class ClassA

T McKeown
  • 12,971
  • 1
  • 25
  • 32