I was studying the use of static keyword and found that if a variable is created as static then one copy of it is created and shared among all the objects of the class.
But the output of below code confused me that why it is not showing incremented value.
public class Test {
static int y = 10;
public static void main(String[] args) {
System.out.println(y);
System.out.println(y+1);
System.out.println(++y);
System.out.println(y--);
}
}
I was expecting the output to be:
10
11
12
12
But the actual output is:
10
11
11
11
Please help me to understand the output.