I feel like I'm missing something here; can someone point out what I'm misunderstanding?!
I've got two classes, an Abstract and a Concrete, as follows:
public abstract class Abstract
{
protected static int ORDER = 1;
public static void main (String[] args)
{
Concrete c = new Concrete("Hello");
}
public Abstract()
{
Class c = this.getClass();
System.out.println(ORDER++ + ": Class = "
+ c.getSimpleName()
+ "; Abstract's no-arg constructor called.");
}
public Abstract(String arg)
{
this();
Class c = this.getClass();
System.out.println(ORDER++ + ": Class = "
+ c.getSimpleName()
+ "; Abstract's 1-arg constructor called.");
}
}
and
public class Concrete extends Abstract
{
public Concrete()
{
super();
Class c = this.getClass();
System.out.println(ORDER++ + ": Class = "
+ c.getSimpleName()
+ "; Concrete's no-arg constructor called.");
}
public Concrete(String arg)
{
super(arg);
Class c = this.getClass();
System.out.println(ORDER++ + ": Class = "
+ c.getSimpleName()
+ "; Concrete's 1-arg constructor called.");
}
}
When I run this I get the following output:
1) Class = Concrete; Abstract's no-arg constructor called.
2) Class = Concrete; Abstract's 1-arg constructor called.
3) Class = Concrete; Concrete's 1-arg constructor called.
My question is this: why doesn't the call to this() from Abstract's String arg constructor call this no-arg constructor on Concrete? Or, perhaps more pertinently, is there any way to get Abstract's String arg constructor to call the no-arg constructor on Concrete, allowing a "proper" chaining of Constructors?
Thanks
Ant.