+ 2

Can we call a constructor through the another constructor from the same class(like function calling) in java?

If yes then How?

30th Mar 2017, 5:27 PM
Giriraj Nagar
Giriraj Nagar - avatar
2 Answers
+ 2
Yes you can. It must be the first call made though. You just use the this keyword and match the signature of the constructor you wish to call. class MyClass { int count; MyClass() { this(42); // More code... } MyClass(int count) { this.count = count; } }
30th Mar 2017, 6:02 PM
ChaoticDawg
ChaoticDawg - avatar