Remember the cycle... First the static code blocks run. Second the instance variables are given default values always After that the constructor and super constructor runs and then the instance variables are initialized to any values provided in construtors or initialization blocks.
The default value of instance variable f which is float is 0.0. So its given that value and when the constructors executes...it prints the default value.
"f" does not exist at the moment you try to use. First, the (implicit) call (chain up to Object) to super() must be executed. Then f exists initialized with the default value.
As anton said,i was expecting this.f cannot reference before this(f) exceution.But this.f is executed fine and gave resul 0.0 before finished this(5) execution.is the above program flow of execution different from the below one.
this program gave me the compile error at line 1 as expected.But i am asking how the first program is executing without an error.Please help me.
See in the first question you are this(5).Here you are epassing a literal. To an overloaded constructor.From there the super class constructor is beging called.After it will come to
System.out.println(this.f);//line 1 this statement.Here replace that statement to this statement. now we can assign any value to instance variable . so try to assign this.f=10;
after execution of this statement the control will go to default constructor.Here if you want you can print.
ONE THING KEEP IN MIND THAT YOU CAN ASSIGN OR YOU CAN A USE(LIKE YOU DID IN THE LAST EXAMPLE OF THE PAGE) INSTANCE VARIABLE AFTER SUPER CLASS CONSTRUCTOR IS EXECUTED . OK
in last example code you did like this .this(f).At this point the super class constructor is not called.That is why you are getting error. [ February 27, 2007: Message edited by: anil kumar ]