i am currently taking java class, and today my teacher said something that my mind didn't accepted i could be wrong. following code ,
class Ab{
int x;
int b;
public Ab(int x, int b){
this.x = x;
this.b = b;
}
public static void main(String[] args){
Ab x = new Ab(4,5); // this is where my teacher confused me
}
}
my teacher said x Ab = new AB(4,5);
will get x object invoking constructor passed in constructor to refer to it with this keyword
, what about anonymous classes like new Ab(2,4);
now what will this keyword
refers to? in my point of view this
inside constructor has no link with reference variable until constructor create the object and return the reference to variable.