Docsity

Java Primitive Type Conversions: Narrowing and Widening, Summaries of Software Development Methodologies

Toggle sidebar
bg1
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;

Partial preview of the text

Download Java Primitive Type Conversions: Narrowing and Widening and more Summaries Software Development Methodologies in PDF only on Docsity!

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;