This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Local chaining of constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Local chaining of constructors" Watch "Local chaining of constructors" New topic

Local chaining of constructors

Patrick Haley

Joined: Sep 15, 2004
Posts: 10
While studying for the SCJP Exam, I read about this technique, which appears to be quite nifty, but I'm wondering what practical purpose it would serve.

Has anyone locally chained constructors in applied code and, if so, to what end?


Wannabe SCJP 1.4<br /> <br />It wasn't raining when Noah built the ark.<br /> --Howard Ruff
C Broussard

Joined: Jun 18, 2004
Posts: 28
When you say locally chain constructors, are you talking about overriding constructor signatures?


public class someobject{
int someobject_value = 0;
public someobject(){
public someobject(int i){
someobject_value = i;

if this is what you're talking about then yes, this is perfectly

hope that helped.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
That's right, although defining more than one constructor isn't "overriding",
it's just defining more than one constructor, and the syntax is:

There is no emoticon for what I am feeling!
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Has anyone locally chained constructors in applied code and, if so, to what end?

Often times you may want several constructors for convenience. By chaining them you can keep the bulk of the code in one constructor.
Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Patrick Haley:
Has anyone locally chained constructors in applied code and, if so, to what end?

Here's some real-world code I wrote the other day.
See if the chaining makes sense to you.

bitguru blog
I agree. Here's the link:
subject: Local chaining of constructors
Similar Threads
About Private Constructors
Can constructors be declared private:If so whar are the advatages
java.util. Missing Resource Exception
adv and disadv of constructor and finalizer method