What are the rules for automatic conversion in Java?
The rules for automatic type conversion in Java are as follows:
- When one of the two operands is of double type, the other operand will be automatically converted to double type.
- If one of the operands is of type float, the other operand will be automatically converted to float type.
- When one of the operands is of type long, the other operand will be automatically converted to long type.
- If one of the two operands is of type int, the other operand will be automatically converted to type int.
- When one of the operands is of type short, the other operand will automatically be converted to type int.
- When one of the operands is of type byte, the other operand will be automatically converted to type int.
It is important to note that if both operands are integers and one exceeds the range of the other, the operand with the smaller range will be automatically converted to the type of the operand with the larger range.