What will be the output of the following statement ? System.out.println(‘a’ + 1);
Answers
Answered by
3
Answer:
Error
Explanation:
a variable is not available so you can't add it with 1.
I think it is helpful please add me to your brain list
Answered by
1
The output of the statement:
System.out.println(‘a’ + 1);
is
a1
- In Java, System.out.println() is a function used to print the argument that is passed to it, to the console.
- General syntax: System.out.println(parameter)
- Any data type which is passed as parameter to this function is first converted to String and then printed to the console.
- In this case, 'a' is converted to String and 1 is also converted to String.
Therefore, it can be written as
"a" + "1"
- In case of Strings, '+' operator is used as a String concatenation operator and it concatenates 2 strings.
Here, "a" + "1" is concatenated to "a1".
- Therefore,
System.out.println(‘a’ + 1);
is same as
System.out.println("a1");
- Hence a1 is printed to the console.
#SPJ3
Similar questions