Wednesday, 23 November 2016

What is the output of following program?

What is the output of following program?

a++ or a-- is postfix operation, meaning that the value of a will get changed after the evaluation of expression.

++a or --a is prefix operation, meaning that the value of a will get changed before the evaluation of expression.

lets assume this;

a = 4;

b = a++; // first b will be 4, and after this a will be 5

// now a value is 5
c = ++a; // first a will be 6, then 6 will be assigned to c
  1. package com.instanceofjava;
  2.  
  3. public class A{

  4.  
  5.  static int a = 1111;
  6.  static
  7.  {
  8.         a = a-- - --a;
  9.  }
  10.     
  11. {
  12.         a = a++ + ++a;
  13.  }
  14.  
  15.  public static void main(String[] args)  {
  16.  
  17.        System.out.println(a);
  18.  
  19.     }
  20.  
  21. }

  1. 2

No comments:

Post a Comment