The statement System.out.println(“four”+2+2); gives the output
Answers
Answer:
Output : four22
Explanation:
In Java, If you trigger a string in the print statement, the data present next to the string will too be treated as a string data.
As in, In the statement System.out.println(“four”+2+2); , the content next to the string "four" is 2 and 2, and they will be treated as "2" and "2"
So, "four"+2+2 will be treated as "four"+"2"+"2", and they will be concatenated resulting four22
Note:
If the statement is System.out.println(2+2+"four"); the answer will be 4Four as 2+2 will be evaluated first resulting 4, and as soon as 4+"four" triggered the string "four", they will get concatenated as a single string.
Program:
public class something
{
public static void main(String []args)
{
System.out.println("four"+2+2);
}
}
Output:
four22
To get a bit clarification on compilation, please do check the attachments given below.
Cheers!!