What will be the output of following Java quiz ?
In following Java program, two JavaQuiz objects are created and a method callAgain() is called to manipulate the value of state variable.
What will be the output when this program is executed ?
Answer
For the first call to callAgain(), the “if” check is false. So, state is just incremented to 2 and printed.
For second call, the “if” condition is true, so callAgain() is invoked one more time. state becomes 6 and is returned, but not stored. When control is returned to second invocation of callAgain(), state is increased to 7.
So, correct answer is “2 7”.
You may also like
Top 10 popular and tricky Java puzzles
© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post