Originally posted by Ryan McGuire:
The this() in line 13 calls the no-argument constructor.
Line 14 sets the instance field called age to the value of the passed in argument called age. The this is required to distinguish the instance field from the method argument of the same name.
Make sense?
Ryan
So your are telling the main use of "this" is distinguish the instance variable from the method argument. Correct me If i'm wrong, instead of assigning "age" to one new variable(x), we can use this operator.
12 public Ryan(int age) {
13 this(); // Do the default initialization.
14 x = age;
15 }
Another doubt in this(); Whether we can have any argument in the this();
this() is mainly to call constructor alone?