InterviewSolution
Saved Bookmarks
| 1. |
If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?(a) Parent *p=child;(b) Parent *p=*child;(c) Parent *p=&child;(d) Parent *p=Child();The question was asked by my school principal while I was bunking the class.My question is from Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» CORRECT CHOICE is (c) Parent *p=&child; Easy explanation - The SYNTAX MUST CONTAIN the base class name first. So that the parent class object pointer can be declared. Then the object is assigned with the derived class object with & symbol. & symbol is added to get the address of the derived class object. |
|