Welcome Guest | Sign in | Register
Variables and Loops - Discussion Page For Q.2980 | 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 ?

public class Test {
public static void main(String... args) {
int a =5 , b=6, c =7;
System.out.println("Value is "+ b +c);
System.out.println(a + b +c);
System.out.println("String "+(b+c));
}
}
A. Value is 67 18 String 13 B. Value is 13 18 String 13
C. Value is 13 18 String D. Compilation fails

Answer and Explanation

Answer:Compilation fails

Explanation:
If the left hand operand is not a String then + operator treat as plus BUT if left hand
operand is a String then + perform String concatenation.

Comment on this Question

Name:

Loading...




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