I can't understand dowen casting and upcasting | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I can't understand dowen casting and upcasting

10th Aug 2016, 2:53 PM
Islam Elzohary
Islam Elzohary - avatar
2 Answers
+ 2
Casting is changing type of variable. There are 2 types of casting 1. Downcasting - cast from parent to child e.g. Object o = new String("a string"); String s = (String)o; 2. Upcasting - child to parent e.g. String s = new String("abc"); Object o = (Object)s; Note that Object is parent of String.
10th Aug 2016, 3:06 PM
WPimpong
WPimpong - avatar
0
good explanation
30th Sep 2016, 4:14 PM
Mark Brown
Mark Brown - avatar