Identify two valid data types for the operands of the addition (+) operator?
Identify two valid data types for the operands of the addition (+) operator?
The addition operator (+) is used to add numbers (numeric data type) and to concatenate strings (string data type). Boolean and array types are not valid operands for the addition operator. Therefore, the valid data types for the operands of the addition operator are string and numeric.
'+' operator in java can be used to add numbers and concatenate strings. Following rules should be considered. Only numbers as operands then result will be a number. Only strings as operands then result will be a concatenated string. so logically the answer is A (string) and C (numeric) because it says valid data type, array is not a data type right?
A and C are the correct answer.
In Java, the addition operator + is used for adding numerical values or concatenating strings.