Accenture Java Programming Practice Question
What is the output of this program? class selection_statements { public static void main(String args[]) { int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) System.out.print(var2); else System.out.print(++var2); } }Answer options
A
3
B
4
C
2
D
1 Observe the if construct. var 2 is assigned 1. 1 does not equal 5, hence else block will get execute
Correct answer: 2
Explanation
Correct answer: 2.