I learned two things:
- The
new
-operator creates a new instance and then the stated connstructor is executed to initialise that new instance - A constructor call (
this()
) creates a new instance.
For my understanding these statements object each other.
For example wouldn't new Example()
create two instances then, because the new
-operator creates one and the constructor calls this()
and creates another? Of course it doesn't but what exactly creates an instance now...?
class Example
{
private boolean _b;
public Example()
{
this(false);
}
public Beispiel(boolean b)
{
_b = b;
}
}