Welcome Guest | Sign in | Register
Variables and Loops - Discussion Page For Q.2983 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Variables and Loops > Questions and Answers

Q: What is the output for the below code ?

1. public class Test {
2. public static void main(String... args) {
3. Integer i = 34;
4. String str = (i<21)?"jan":(i<56)?"feb":"march";
5. System.out.println(str);
6. }
7. }
A. Feb B. Jan
C. March D. Compilation fails with an error at line 4

Answer and Explanation

Answer:Feb

Explanation:
This is nested conditional with unbox. (i<21) is false goto (i<56), (i<56) is true so result is "feb".

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.