Java is the future !: Quiz of the Day | December 3, 2010

Friday, December 3, 2010

Quiz of the Day | December 3, 2010

What will be the output when you compile and execute the following program? 
Choose one answer. 
a. Prints true 
b. Prints false 
c. Prints 9 
d. Prints 2 
e. Compiler error : Incorrect declaration of main method 
f. None of these

Solution : Choice F is the correct answer. 

The code does not compile because the && operator works only with boolean operands. If both operands are true, the && operator returns true and false in all the other cases. In this case, integer operands arepassed to the && operator, so the code does not compile. Since the code does not compile, choices A to D are incorrect.

Choice E is incorrect because there is nothing wrong with the declaration of the main method. The modifiers public and static can appear in any order. Also, the main method takes a String[] as the argument.

Source : "Facebook Community"

No comments:

Post a Comment