From the point of view of compiler behavior and java class design what would be the justification for using the Instance Launcher block?
Considering the following class:
class Caneta {
public Caneta() {
System.out.println("Caneta:constructor");
}
public Caneta(String a) {
System.out.println("Caneta:constructor2");
}
/** ################################### */
/** Inicializador de Instância */
/** ################################### */
{
System.out.println("Caneta:init1");
}
/** ################################### */
/** Inicializador de Instância */
/** ################################### */
{
System.out.println("Caneta:init2");
}
/** ################################### */
public static void main(String[] args) {
new Caneta();
new Caneta("aValue");
}
}
The output of the previous code is:
Caneta:init1
Caneta:init2
Caneta:constructor
Caneta:init1
Caneta:init2
Caneta:constructor2
Why do you think you need an instance initializer if you can initialize your instances using constructors?
Reference:
[MALA GUPTA, 2015], OCP Java SE 7 Programmer II
Certification Guide : PREPARE FOR THE 1ZO-804 EXAM