+ 2

casting

whay we use the casting ?

8th Jan 2017, 10:24 AM
Ehsan
3 Answers
+ 1
please help me!!!
8th Jan 2017, 10:25 AM
Ehsan
+ 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
8th Jan 2017, 10:35 AM
Stefan Milosavljevic
Stefan Milosavljevic - avatar
+ 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
8th Jan 2017, 11:31 AM
Aboli Nathu Jori
Aboli Nathu Jori - avatar