What is the result?

Given the code fragment:
<code>
int a = 0;
a++;
System.out.println(a++);
System.out.println(a);
</code>
What is the result?

Given the code fragment:

int a = 0;
a++;
System.out.println(a++);
System.out.println(a);

What is the result?

A.
12

B.
01

C.
1

D.
2
2

Explanation:

The first println prints variable a with value 1 and then increases the variable to 2.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


koshzerg

koshzerg

Shouldn’t the answer be “1 2” ?

Kalil Peixoto

Kalil Peixoto

Do you mean with spaces between koshzerg?

Actually it should be `print` rather than `println`.

sully

sully

1
2 is what would be printed. Since ln is there a new line would be used.