1-
class
Test {
static
String s;
static {
s = "s initialized by static initializer";
System.out.println(s);
}
Test() {
s = "s initialized by constructor";
System.out.println(s);
}
public static void main(String[] args) {
System.out.println(s);
}
}
Debugging this code I got "s initialized by static initializer";
twice ! Why didn't call the constructor assigned ???
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2-
class Base {
Base(String s) {
System.out.println("s of Test: " + s);
}
}
class Test extends Base {
String s = "Original string of Test";
{
s = "s initialized by Instance initializer of Test";
System.out.println(s);
}
Test() {
super(s);
s = "s initialized by constructor of Test";
System.out.println(s);
}
public static void main(String[] args) {
Test t = new Test();
}
}
Compiled got an error in Super(s) !!! But it's supose to call the string version of the contruct of the Base and execute "System.out.println("s of Test: " + s);"
Someone can tell me WHY ???
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Thx in advance !