What is the output of following block of program ? boolean var = false; if(var = true) { System.out.println("TRUE"); } else { System.out.println("FALSE"); }(a) TRUE (b) FALSE (c) Compilation Error (d) Run-time Error

(a)
EXPLANATION: The code compiles and runs fine and the 'if' test succeeds because 'var' is set to 'true' (rather than tested for 'true') in the 'if' argument.

Showing Answers 1 - 5 of 5 Answers

SG

  • Aug 4th, 2005
 

You can have only test condition statements in "if" statement.So the answers will be -c. Compilation Error.

  Was this answer useful?  Yes

jacob

  • Apr 10th, 2006
 

the output is " true " since in true is assigned in if statement and the if condition becomes true.

  Was this answer useful?  Yes

animesh kalita

  • Jul 25th, 2006
 

compilation error.because boolean and var are not defined

  Was this answer useful?  Yes

Prasanth Narayan

  • Oct 12th, 2006
 

TRUE

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions