What could be output of the following fragment of code?
public class Test{
public static void main(String args[]){
String x = "hellow";
int y = 9;
System.out.println(x += y);
}
}
public class Test{
public static void main(String args[]){
String x = "hellow";
int y = 9;
System.out.println(x += y);
}
}A. Throws an exception as string and int are not compatible for addition
B. hellow9
C. 9hellow
D. Compilation error
E. None of these
Answer: Option B

yes, we can add two different datatype and also concate with the string
String s="Java";
int a=10;
float b=10.6f;
System.out.println(s+a+b);
I have a boubt can we add different data types??
x +=y that implies x=x+y
=>x=hellow
=> y=9
x=hellow+9
answer: hellow9
9 is concatenated with hellow
plz give the solution.............
Hi Arpitha,
Here, program is printing value of a variable with System.out.println. So, need of statement under " ". You can run this program by yourself you can understand it.
Here println = Print with a new line.
Yes it is an error. Because in the printing statement " " are missing.
So it will not print.
Yes Mr. Samil you are correct we are updating our answer. Thanks!
Wrong answer,Correct answer is B.