[Logo]
Forums Register Login
Overload constructor
Hi Folks,

I am started to read and practice java from last week,

Could anyone give some explantion with example for the following Qs

how come the constructor invokes an overloaded constructor in the same class?
If it does whats the priority?
 

how come the constructor invokes an overloaded constructor in the same class?
If it does whats the priority?


Look at the following code example:



Output:
SuperClass String arg constructor called
String arg constructor
double arg constructor
int arg constructor

And finally the rule of thumb :
1- Call to super() or this() must be first statement of any constructor.
2- In any constructor there can be either super() of this() not both.

You can see the output of the example how the constructor completion takes place from top to bottom (from super class to sub class);

I think this could be answer to solve the construtor puzzle for you!

Thanks and Regards,
cmbhatt
thanks Much Chan
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 20, 2017 16:14:12.