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.
Loading...
Related Quiz
- How many else if blocks can be used after an if block?
- The method read() of FileReader class returns ________ when the end of the file is reached.
- Which of the following character stream classes should be used to read characters, arrays, and lines efficiently?
- Which method is used to execute SQL queries in JDBC?
- If a and b are boolean expressions, then a & b is true only if ______.