
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Q. In Java, for the primitive types, there are two kinds of type conversions. Please describe each briefly with a simple example. Ans: The two types of conversion for primitive types are
1. Narrowing: Also known as explicit type casting. It is conversion from data type having larger range to data type having smaller range provided both data types are compatible. Such conversion is explicit, that is, you have to do it yourself by casting. Compiler won’t do it for you. General form: destination value= (target type) source value Example: int a; long b; a =(int) b; 2. Widening: Also known as implicit type casting. It is conversion from data type having smaller range to data type having larger range provided both data types are compatible. Such conversion is implicit, that is, the compiler will automatically do it. General form: destination value= source value Example: int a; long b; b = a;