Thursday, 26 May 2016

Can we call one constructor from another if a class has multiple constructors? How?



Yes,  we can call one constructor from another in the same class, or call the super class , with the following  restriction:

1. It has to be the first line of code in the calling constructor.

2. It cannot have any implicit or Explicit reference to "this". So you cannot pass an inner class (even an anonymous or if it reference any instance methods), or the result of a non-static method call, as a parameter.


No comments:

Post a Comment