1
visibility

Give output of the following method:
public static void main(String[] args){
int a = 5;
a++;
System.out.println(a);
a -= (a–) – (–a);
System.out.println(a);
}

  • 6
    3

  • 5
    2

  • 5
    3

  • 6
    4

a++ increments a from 5 to 6. The first print statement prints the value of a which is 6.
a -= (a–) – (–a);
is equivalent to
a = a – ( (a–) – (–a) )
a = 6 – ( 6 – 4 )
a = 6 – 2
a = 4