Why casting is needed in JAVA ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why casting is needed in JAVA ?

byte a = -128; byte b = (byte) (a/2); Can we write it without byte part ? On which cases casting is needed?

31st Jan 2017, 5:00 AM
Rashmi Ranjan Bisoi
Rashmi Ranjan Bisoi - avatar
1 Answer
+ 2
if the destination variable is smaller than source variable then we need casting...like.. if u want to convert long into int or int into byte
1st Feb 2017, 5:50 AM
Somnath Ghosh
Somnath Ghosh - avatar