Type casting in Java:
Automatic, non-explicit change of data type is known as Conversion.
Type casting is of two types.
1. Widening / Implicit / Automatic type casting
2. Narrowing / Explicit / Manual type casting.
1 Implicit type casting:
Variable of smaller capacity can be assigned to another variable of bigger capacity.
byte -> short -> char -> int -> long -> float -> double
<span style="color: #000000;">int i = 50;
double d = i;</span>
2 Explicit type casting:
Whenever a larger data type is converted to smaller type then we have to explicitly specify the type case operator.
double -> float -> long -> int -> char -> short -> byte
<span style="color: #000000;">double d= 100;
i = (int) d;</span>
Note: If you like selenium99.com and want to contribute any articles, then please send your articles to email@example.com.
If you want to improve this article or find any mistake in the article, then please use comment box to share your feedback.
Tags: Type casting in Java