3,796 views
5 votes
5 votes

In Java, after executing the following code what are the values of x, y and z?

int x,y=10; z=12;

x=y++ + z++;

  1. x=22, y=10, z=12
  2. x=24, y=10, z=12
  3. x=24, y=11, z=13
  4. x=22, y=11, z=13

3 Answers

Best answer
8 votes
8 votes

Answer is [D]  x=22, y=11, z=13

selected by
1 votes
1 votes
x = y++ + z++;

As in post increment operator, first the value is assigned and then it is incremented, this statement can be re-written as:

x = y + z;
y = y++;
z = z++;

So, the value of x = 10 + 12 = 22, y = 10 + 1 = 11 and z = 12 + 1 = 13.

Option (D) is correct.

Answer:

Related questions

7 votes
7 votes
2 answers
1
go_editor asked Jun 23, 2016
3,787 views
Find the output of the following Java code line System.out.printIn(math.floor(-7.4))-7-8-7.4-7.0
0 votes
0 votes
1 answer
2
admin asked Apr 1, 2020
946 views
Is null an object?YesNoSometimes yesNone of these
0 votes
0 votes
1 answer
3
admin asked Mar 31, 2020
683 views
Earlier name of Java programming language was:OAKDNetbeanEclipse
0 votes
0 votes
1 answer
4
admin asked Mar 31, 2020
1,000 views
Which of the following is a platform free language?JAVACAssemblyFortran