0
0
Javaprogramming~5 mins

Type promotion in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is type promotion in Java?
Type promotion is when Java automatically converts a smaller data type to a larger data type to avoid data loss during operations.
Click to reveal answer
beginner
Which data types are involved in type promotion during arithmetic operations?
Java promotes byte, short, and char to int before performing arithmetic operations.
Click to reveal answer
beginner
What happens when you add a byte and an int in Java?
The byte is promoted to int, and the result is an int.
Click to reveal answer
intermediate
Explain type promotion with an example:
byte b = 10; int i = b + 5;
Here, byte b is promoted to int before addition. So, b + 5 is int + int, resulting in an int assigned to i.
Click to reveal answer
beginner
Does Java promote boolean types during type promotion?
No, boolean types are not promoted because they represent true/false values, not numbers.
Click to reveal answer
Which type does Java promote byte and short to during arithmetic operations?
Adouble
Bint
Cfloat
Dlong
What is the result type of the expression: byte b = 5; b + 10?
Abyte
Bshort
Cint
Dlong
Does Java automatically promote boolean values during arithmetic operations?
ANo, boolean is not promoted
BYes, to byte
CYes, to int
DYes, to double
If you add an int and a long, what is the type of the result?
Aint
Bdouble
Cfloat
Dlong
Which of these is NOT automatically promoted by Java during arithmetic operations?
Aboolean
Bshort
Cchar
Dbyte
Explain what type promotion is in Java and why it is important.
Think about how Java handles small numbers when doing math.
You got /4 concepts.
    Describe what happens when you add a byte and an int in Java.
    Consider how Java treats smaller types in expressions.
    You got /4 concepts.