1.

Which among the following is safe?(a) Upcasting(b) Downcasting(c) Both upcasting and downcasting(d) If upcasting is safe then downcasting is not, and vice versaI have been asked this question in unit test.Asked question is from Upcasting in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (a) UPCASTING

The explanation: The upcasting is always safe since the derived TYPE or the SMALLER type is converted into the base type or the larger size. This results in ALLOCATING a smaller size data into bigger type data. No data is lost in casting, hence safe.



Discussion

No Comment Found

Related InterviewSolutions