Output of java program


#1

What is the output of following program?

package com.instanceofjava;

public class A{

static int a = 1111;
static
{
a = a-- - --a;
}

{
a = a++ + ++a;
}

public static void main(String[] args) {

   System.out.println(a);

}

}


#2

The output of the above java class is 2.
cos there is no static keyword above this block {
a = a++ + ++a;
}.
so only, a = a-- - --a; gets evaluated and give ans 2.
if static keyword is placed above second block then the result will be 6.