0

what does upcasting/downcasting even do??

im just completely confused as to what it does. what the hell is its functionality

16th Apr 2020, 7:37 AM
ana.ashye
2 Respuestas
+ 1
casting is used to change the type of a value. upcasting changes the value to a more complex type (e.g. integer to double). downcasting change the value to a simpler type (e.g double to integer)
16th Apr 2020, 8:07 AM
Lisa
Lisa - avatar
+ 1
Up casting : in casting, if you cast parent class reference to child class is called up-casting.. Or also casting from lower type data type to upper datatype is also called up-casting.. Ex: class A{ .. } class B extends A{ ... } Here, A a=new A(); B b=new B(); b=(A) a; //upcasting, but not always possible.. int c=5; double d=(double) c; Down casting: just in reverse, casting child to parent is down casting.. Ex: A aa=(B) b; int i=(int) d; //here double d=1; Hope this helps... Edit:
16th Apr 2020, 8:13 AM
Jayakrishna 🇮🇳