14.ThisAndMethodsWithObjectReference
14.ThisAndMethodsWithObjectReference
Brothers Java
Show Room kphb-Hyderabad
This
“this “ is keyword of reference type
“this” is existed implicitly in every instance method of the class
“this” is always used to refer current object by hold its hash
code
Whenever both local and instance fields declare with the same in
order to make the differentiation between local and instance
fields, Then we have make use “this” for an instance field
1|Page
SSSIT Computer Education Besides R.S.Brothers Java
Show Room kphb-Hyderabad
boolean compare(Sample o)
//non static mtd | instance mtd
{ if(x==o.x && y==o.y)
return true;
else
return false; }
2|Page
SSSIT Computer Education Besides R.S.Brothers Java
Show Room kphb-Hyderabad
boolean b=s1.compare(s2);
if(b==true)
System.out.println("Both are Same");
else
System.out.println("Both are not Same");
}
}
4|Page