Q-1) What will be the output of the following program?
int i = 4;
int j = 21;
int k = ++i * 7 + 2
System.out.println("k = " + k);
A) K=37
B) Program does not compile
B) K=28
C) k=0
Answer: A) K=37
Q-2) What will be the output of the following program?
int input = 7;
int output = ++input + ++input + ++input;
System.out.println(output);
A) -20
B) 109
B) 27
C) 35
Answer: C) 27
Q-3) What will be the output of the following program?
int i, j, k, l = 0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
A) 0
B) 1
B) 2
C) 5
Answer: B) 1
Q-4) What will be the output of the following program?
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
A) a = 2
b = 3c = 4
d = 1
B) a = 2
b = 3
c = 4
d = 1
C) Program does not compile.
D) a = 1
b = 2
c = 4
d = 2
Answer: A) a = 2
b = 3c = 4
d = 1