Hi all,
I do not understand when instance variable gets initialized before constructor or after the constructor
here is the following code:
class Test{
int a=6;
Test(){
this(a);
}
Test(int x){
)
public static void main(
String args[]){
Test t=new Test();
}
this code give compiler error saying that a has not been initialized.So i thought that constructors are executed before instance variables.
But this code compiles properly
public class Test{
int i;
Test(){
i++;
}
public static void main(String args[]){
Test t=new Test();
S.o.p(t.i);
}
o/p is 1
Can anyone what's happening in these two codes.
Regards
Neha