ProgrammingVery hardInfosys DSE · Wipro Elite

What is printed?

What is printed?
short s = 1;
s = (short) (s + 1);
char c = 'A';
c += 1;
c++;
System.out.print(s + " " + c + " " + (c + 1));
  1. A. 2 C C
  2. B. 2 C 68
  3. C. 3 C 68
  4. D. 2 B 67

Correct answer: B. 2 C 68

s is 2; c goes A to B to C via compound assignment and ++ (no cast needed); in the concatenation c prints as C while c + 1 is int arithmetic: 67 + 1 = 68.

More OOP with C++ and Java questions

Exams that ask this topic