0

Why do you need casting and where it uses?

I'd like to know why you need casting in explicit.

9th Aug 2016, 8:45 AM
Justin Suh
Justin Suh - avatar
2 Respostas
+ 4
Casting is used when you need some data type to converted into another data type , suppose you have a string that contains number , (String Text="123456") and you want to store the numbers (for some calculations purpose or whatever) into a integer data type (int number = Text). this is where you need casting .. because , integer data type and String(which is an abstract data type) are not compatible normally (for obvious reason) ..so you need to cast it explicitly (int number=Integer.pasreInt(Text);
9th Aug 2016, 11:38 AM
sohel
sohel - avatar
+ 3
Because computer can not recognize string,float,int,or else, if we don't define the type, it will confuse the computer, so we have "casting" to make the data specific. Is it correct?
9th Aug 2016, 11:35 PM
solsir