+ 2
casting
whay we use the casting ?
3 Réponses
+ 1
please help me!!!
+ 1
example : you have app that converts euros in dolars. user can insert value in some edittext widget and when you colect that value it is of type string and you cant manipulate with it - multiplay it with excange rate - because it is a word, not a number. so you have to cast it to some number format - float or double ror example in order to do your calculation
+ 1
casting means is taking an Object of one particular type and “turning it into” another Object type. This process is called casting a variable.
for e.g.:
Base b = new Derived(); //reference variable of Base class points object of Derived class
Derived d = b; //compile time error, requires casting
Derived d = (Derived) b; // type casting Base to Derived