InterviewSolution
Saved Bookmarks
| 1. |
If class C inherits class B and class B inherits class A ________________(a) Class C object can be upcasted to object of class B only(b) Class C object can be upcasted to object of class A only(c) Class C object can be upcasted to object of either class A or B(d) Class C object can’t be upcastedThis question was addressed to me in a national level competition.My doubt stems from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT OPTION is (c) Class C OBJECT can be upcasted to object of EITHER class A or B The explanation is: Both class A and B are parent classes of class C. Class C object hence can be upcasted to any of those class objects. It is not compulsory to upcast to nearest parent. |
|