Java / Casting
for e.g.
for e.g.
No.not possible.
The conversion of data from one data type to another data type is termed as type casting. Type casting refers to changing the type of the data.
Note that using type casting, only type of the data can be changed not the data itself.
There are 2 types.
Primitive casting refers to the casting between primitive data types. For example int to float.
Derivd casting refers to the casting between derived types/object.
The data is implicitly casted from small sized primitive type to big sized primitive type. This is called auto-widening. i.e The data is automatically casted from byte to short, short to int, int to long, long to float and float to double..
You have to explicitly cast the data from big sized primitive type to small sized primitive type. i.e you have to explicitly convert the data from double to float, float to long, long to int, int to short and short to byte This is called explicit narrowing.
An object of sub class type can be automatically casted to super class type. This is called auto-up casting.
An object of super class type should be explicitly casted to sub class type, It is called explicit down casting.