• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Overload constructor  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Sathya Shanmugam
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Much Chan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!