+ 2

can anyone give examples for downcasting here ?

4th Jul 2016, 2:59 PM
Iqbal
2 ответов
- 1
class Cat extends Animal {} class MyClass { public static void main (String [] args){ Cat myCat = new Cat (); Animal animal = (Animal) myCat; //is it upcasting? i don't remember. lol //if the above example is upcasting Animal animal = new Animal (); Cat myCat = (Cat) animal; } }
10th Jul 2016, 11:07 AM
Harry Marwanto
Harry Marwanto - avatar
- 1
for downcasting is require to do casting explicitly but for upcaating is not necessary to do explicitly jvm will automatically do it implicitly. int price = 22 ; double value = price ;// upcasting. is not necessary explicit double value = 32.45 ; int price = (int) value // downcasting
17th Jul 2016, 7:56 PM
Rao Arsalan
Rao Arsalan - avatar