static initialization
Hello Guys!
I磎 curious about the following behavior below.
public class Car {
static String name = "NULL";
static {
name = "MyCar";
}
public static void main(String[] args) {
System.out.println(Car.name);
}
}
Here, any doubts.
I receive "MyCar" as out, okay!
But, when I change the code for the following...
public class Car {
static {
name = "MyCar";
}
static String name = "NULL";
public static void main(String[] args) {
System.out.println(Car.name);
}
}
I磛e got receive "NULL" as out.
I think of this occour because of the order of the instrution line, but I磎 not right!
Thanks
Message was edited by:
ROBEA
[796 byte] By [
ROBEAa] at [2007-11-27 6:09:58]

> Hello Guys!
> I磎 curious about the following behavior below.
>
> public class Car {
> static String name = "NULL";
> static {
> name = "MyCar";
> }
> public static void main(String[] args) {
> System.out.println(Car.name);
> }
> }
>
> Here, any doubts.
> I receive "MyCar" as out, okay!
>
> But, when I change the code for the following...
>
> public class Car {
> static {
> name = "MyCar";
> }
> static String name = "NULL";
> public static void main(String[] args) {
> System.out.println(Car.name);
> }
> }
>
> I磛e got receive "NULL" as out.
>
> I think of this occour because of the order of the
> instrution line, but I磎 not right!
Why are you not right?