Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
this time my this keyword refers to the b object of class Board, isn't it??
and if i use 'b' instead of this, is that right??
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Greg Brannon wrote:You called your constructor from somewhere else, using something like:
Board someName = new Board();
So, when you enter the constructor to create the someName Board object, the keyword 'this' IN THIS SPECIFIC CASE refers to the object someName.
The keyword 'this' relieves you of having to know the name or instance of the object being acted on.
Punit Jain wrote:i don't want to substitute it with something else, but actually i asked this question to clear use of 'this' keyword.
and the first line of the code is commented, please ignore it, i am calling the constructor from some other class like this:
Board b = new Board();
and as you said at this time my this keyword refers to the b object of class Board, isn't it??
and if i use 'b' instead of this, is that right??
Punit Jain wrote:okay, got it thanks..
finally: this refer to current object
not object...?
Punit Jain wrote:i mean if i create more than one instances of a class, that time this refers to the current instance, isn't it??
Punit Jain wrote:okay got it, and i created three instances like you said
Foo f1 = new Foo();
Foo f2 = new Foo();
Foo f3 = new Foo();
and Foo class has a constructor and no methods, so which instance 'this' will refer first, i mean which instance/object will execute first?
Punit Jain wrote:okay got it, and i created three instances like you said
Foo f1 = new Foo();
Foo f2 = new Foo();
Foo f3 = new Foo();
and Foo class has a constructor and no methods, so which instance 'this' will refer first, i mean which instance/object will execute first?
Punit Jain wrote:okay the output is 1 2 3.
and you initialize the
int fooVariable = 10;
again, but it still printing 1 2 3, because you use this keyword here