public class Ex14 {
static String strDef = "At the point of definition";
static String strBlock;
{ strBlock = "In a block";}
public static void main (String [] args){
System.out.println(Ex14.strDef);
System.out.println(Ex14.strBlock);
Ex14 test = new Ex14();
System.out.println(test.strBlock);
System.out.println(Ex14.strBlock);
}
}
Result:
$ java Ex14
At the point of definition
null
In a block
In a block
If I switch the block with the commented one, both statements are printed. In other words, I just
Well, I can't catch what is going on here.
Questions:
Inside the initializer block the variable is non-static. If it is not anyhow mixed with that static declaration, why the compiler didn't even warn me?
When an instance was created, strBlock is not null anymore. I can't catch why?
Anyway, I can't understand anything here. Please, could you clarify it somehow?