Believe it or not, I don't know this before.
find it from stackoverflow as below,
http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java
find it from stackoverflow as below,
http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java
Yes, it is possible:
public class Foo
{
private int x;
public Foo()
{
this(1);
}
public Foo(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.
Comments
Post a Comment