Considering these variable declarations, which of the following statements are correct?

byte b = 1;
char c = 1;
short s = 1;
int i = 1;
Explanation
1. In operations with two operands both are promoted to the most broad of their types. Therefore, result will have that most broad type.
2. In Java Virtual Machine it is impossible to add something to byte variable without promoting byte to int. It is also true for char type.
3. But += and <<= operations will be successful as they implicitly do type conversion.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes