What does return this statement do in this line? I've Googled a lot but found no relevant answers regarding this :( There is a mistake in the setA method but that is intentional.
E show() {
return this;
}
Here is the full code, it is working fine.
public class E{
int a;
public int getA() {
return a;
}
public void setA(int a) {
a = a;
}
E show() {
return this; //What is the role of this line?
}
public static void main(String[] args) {
E obj = new E();
obj.setA(10);
System.out.println(obj.getA());
E obj2 = obj.show();
System.out.println(obj2.getA());
}
}
Here is the output
0
0