Ankit Garg wrote:The loop has also finished so x will again be set to 0 and gc will be set to true.
so the output would be "true 0"
Rajshekhar Paul wrote:But inside the first if block, x will be incremented. So, in the second if block, x will not be 0.
Kamil Wojcik wrote:I don't get that output, everytimes it's different answer. Is it possible to get such question on the exam? (I mean with random answers).
Ankit Garg wrote:No that will not happen. The if condition will be false as gc will be false till now.
A.true will never be output
B.true will be output at least once
C.if true and false are both output,their respective values for x can be the same.
D.if true and false are both output,their respective values for x can never be the same.
E.This code will not compile
F.A given value for x can never be output more than twice
Rajshekhar Paul wrote:@Cristian
Why are you with the impression that the garbage collector will do it's job during the for loop execution?
Ankit Garg wrote:... In fact usually you don't need to call System.gc on to free memory. ..