This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overload constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overload constructor" Watch "Overload constructor" New topic
Author

Overload constructor

Sathya Shanmugam
Ranch Hand

Joined: Mar 02, 2007
Posts: 45
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?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

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


cmbhatt
Sathya Shanmugam
Ranch Hand

Joined: Mar 02, 2007
Posts: 45
thanks Much Chan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overload constructor