How does the compiler resolve the "+" operator when used with different data types (e.g., String and int)?

  • It performs the operation based on the type of the first operand and ignores the second operand's type.
  • It throws a compilation error because the + operator cannot be used with different data types.
  • It throws a runtime error because the + operator is ambiguous with different data types.
  • It uses type conversion to promote one of the operands to the type of the other operand, and then performs the operation.
It uses type conversion to promote one of the operands to the type of the other operand, and then performs the operation. For example, if you add a string and an int, the int is converted to a string, and string concatenation is performed. If you add two integers, normal addition is performed.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *