Skip to main content


Showing posts from November, 2014

How do I call one constructor from another in Java?

Believe it or not, I don't know this before.
find it from stackoverflow as below,

Yes, it is possible: publicclassFoo{privateint x;publicFoo(){this(1);}publicFoo(int x){this.x = x;}} To chain to a particular superclass constructor instead of one in the same class, use super instead of this. Note that you can only chain to one constructor, and it has to be the first statement in your constructor body.