M
Michael Boocher via JavaKB.com
I ran into a strange initialization order that was in my mind, counter
initutive. What I am looking for is for anyone to perhaps offer an
explanation to this snipet of code.
############### InitializeTest.java ########################
public class InitializeTest extends TestAbstract {
private String TheData = "Default Value -- Why THIS?";
public static void main(String[] args){
InitializeTest IT = new InitializeTest("Some Default Value");
System.out.println(IT);
}
public InitializeTest(String InitialValue){
super(InitialValue);
}
public void ForwardCall(String pData) {
// Use to initialize Data.
TheData = pData;
}
public String toString(){
return TheData;
}
}
############### TestAbstract.java ########################
public abstract class TestAbstract {
public TestAbstract(String Data){
ForwardCall(Data);
}
public abstract void ForwardCall(String Data);
}
Now, I know why it is happening I understand that the constructor order is
a bit off. And that is why the code in the Extended class is being called
before the class is actually instantiated. But I wonder if this is
actually the intended result.
This is more of a cute dicussion thread than anything else.
Enjoy.
initutive. What I am looking for is for anyone to perhaps offer an
explanation to this snipet of code.
############### InitializeTest.java ########################
public class InitializeTest extends TestAbstract {
private String TheData = "Default Value -- Why THIS?";
public static void main(String[] args){
InitializeTest IT = new InitializeTest("Some Default Value");
System.out.println(IT);
}
public InitializeTest(String InitialValue){
super(InitialValue);
}
public void ForwardCall(String pData) {
// Use to initialize Data.
TheData = pData;
}
public String toString(){
return TheData;
}
}
############### TestAbstract.java ########################
public abstract class TestAbstract {
public TestAbstract(String Data){
ForwardCall(Data);
}
public abstract void ForwardCall(String Data);
}
Now, I know why it is happening I understand that the constructor order is
a bit off. And that is why the code in the Extended class is being called
before the class is actually instantiated. But I wonder if this is
actually the intended result.
This is more of a cute dicussion thread than anything else.
Enjoy.