1

I tried to run the below code

static int j = f();
static int i = 10;
static int f(){
    return i;
}

public static void main(String[] args) {
    System.out.println("i="+i);
    System.out.println("j="+j);
}

It produces the output as

i=10
j=0

Can anyone explain why is j=0 ?

deep
  • 1,586
  • 1
  • 18
  • 29

1 Answers1

2

i = 10 runs after the call to f() (because that's the order you wrote it in in source)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964