Howdy!
Raghavan asked:
What exactly is the instance block?
An instance block is for code that shall be the same for all constructors.
It will be executed after the call for super but before the rest of the constructor runs.
When you have overloaded constructors, then you could put the code to be shared into the instance block.
Example:
prints:
fish constructor
Instance Block providing Nemo with 3 stripes.
nemo constructor with int
nemo constructor parameterless
Nemo with 6 fins and 3 stripes.
fish constructor
Instance Block providing Nemo with 3 stripes.
nemo constructor with int
Nemo with 7 fins and 3 stripes.
The two constructors share the instance block, so every Nemo got 3 stripes and we get an output of this.
Yours,
Bu.