How external type casting works in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How external type casting works in java?

Can anyone explain me how external type casting exactly works. Actually while reading a book of java I couldn't understand the following text " if the size of whole number is too large to fit into the target integer type, then value will be reduced modulo the target type's range" please can anyone explain me this thing with an example.

16th Feb 2017, 6:48 AM
Ratnadeep Dey
Ratnadeep Dey - avatar
1 Answer
+ 5
let's imagine that the type Int can only fit numbers from -10 to 10 if you try to put 23 into the type int (which now only stores numbers <=10) the computer will do this: 23(your number)%10 (max storage) = 3 that way the number 3 will be stored in you variable if course the type int is able to store much higher numbers, I just used 10, so it's easier to understand hope this helps ^^
16th Feb 2017, 6:53 AM
Kamil
Kamil - avatar