
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Java supports two types of conversions for primitive data types: narrowing and widening. Narrowing, also known as explicit type casting, involves converting a larger data type to a smaller one. Widening, on the other hand, is an implicit conversion from a smaller data type to a larger one. Brief descriptions and examples of each type of conversion.
Typology: Summaries
1 / 1
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;