Hi guys
Could anyone explain me the behaviour of this code?
1.public class A {
2.int a=v();
3.int x=1000;
4.int b=v();
5.public void v() {
6.System.out.println("x is"+x);
7.return x;
8. }
9.public static void main(
String as[]) {
10.A aobj = new A();
11.}
12.}
when i compile and run this code it first prints x is 0
then it prints x is 1000;
I dont understand how it says x is 0? once the v() method is invoked, directly it goes to that method and i think during this the compiler doesnt have any idea about x.Then how it assumes x to be an integer and gives its default value?
But if i change the line 2 as
int a=x;
it says illegal forward reference.
could anyone explain me why?
Thanx.