Why casting is needed in JAVA ? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antwort
+ 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