Showing posts with label explicit typecasting. Show all posts
Showing posts with label explicit typecasting. Show all posts

Sunday, 14 November 2010

Typecasting

Typecasting in Java or any other programming language for that matter, can thought of in this way. Consider pouring a big bucket full of water into a smaller empty bucket. Most of the water would probably fall down due to spillage. Similarly in Java, if you assign a "double" value into an "integer", there could be loss of data or error. Thus such an assignment needs typecasting.
Whereas when you pour water from a small bucket into a bigger empty one, all the water would easily fill into the bucket. Just the same way, an "integer" value can be assigned into a "double" without the need for an explicit typecasting.
Hope this explanation is simple enough for novices in Programming to understand.