Java Technical Question:
Download Questions PDF

Explain widening conversion and Narrowing conversion?

Answer:

For a primitive data types, a value narrower data type can be converted to a value of a broader data type without loss of information. This is called Widening conversion. For example an int is directly converted to a double without first having to convert it to a long and a float.

Converting from a broader data type to a narrower data type is called narrowing conversion, which can result in loss of information. For example conversion between char and byte and short are narrowing conversions. For example byte takes 8 bits, short takes 16 bits, int takes 32 bits, long takes 64 bits. Conversion of short to int or int to long is widening conversion and conversion of int to short is a narrowing conversion.

Download Java Technical Interview Questions And Answers PDF

Previous QuestionNext Question
How to use beans in JSP?What is a StringBuffer class and how does it differ from String Class?