Test Series - oops

Test Number 70/78

Q: What is upcasting?
A. Casting subtype to supertype
B. Casting super type to subtype
C. Casting subtype to super type and vice versa
D. Casting anytype to any other type
Solution: The upcasting concept includes only the casting of subtypes to the super types. This casting is generally done implicitly. Smaller size types can fit into larger size types implicitly.
Q: Which property is shown most when upcasting is used?
A. Code reusability
B. Code efficiency
C. Complex code simple syntax
D. Encapsulation
Solution: The code written using upcasting mostly shows complex code in simpler syntax features. This is because the upcasting concept can be applied as polymorphism and to group the similar type of objects.
Q: 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();
Solution: 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.
Q: Which among the following is true?
A. Upcasting is possible only for single level inheritance
B. Upcasting is possible only for multilevel inheritance
C. Upcasting is possible only for multiple inheritance
D. Upcasting is possible for any type of inheritance
Solution: The type of inheritance doesn’t matter with the upcasting concept. Upcasting applies to all types of inheritance. Any derived class object can be upcasted to any of its base class object.
Q: If multiple inheritance is implemented, which upcasting will be correct?
A. Upcast to first base class listed in inheritance
B. Upcast to send base class listed in inheritance
C. Upcast to any base class
D. Upcast is not possible
Solution: The upcasting of derived class object is possible to any base class. This is because the base class object can represent any of its derived classes using upcasting.
Q: 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 versa
Solution: 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.
Q: Upcasting is _____________________ without an explicit type cast.
A. Always allowed for public inheritance
B. Always allowed for protected inheritance
C. Always allowed for private inheritance
D. Not allowed
Solution: The public inheritance shows the most flexible is-a relationship. Hence explicit type casting is not required. Implicit type casting is done by the compiler.
Q: Which concept is needed because of implicit type casting use?
A. Static binding
B. Dynamic binding
C. Compile time binding
D. Source code binding
Solution: Since the implicit type casting allows casting of a base class pointer to refer to its derived class object or even base class object. We need dynamic type casting so that the references can be resolved during execution of program.
Q: Which among the following is true for upcasting in inheritance?
A. Downward to the inheritance tree
B. Upward to the inheritance tree
C. Either upward or downward
D. Doesn’t apply on inheritance
Solution: The upcasting concept in inheritance is always applied upward the inheritance tree. The derived class objects can be type casted to any of its parent class type. Since is a relationship applies in general inheritance.
Q: When are the pointer types known for upcasting the objects?
A. Compile time
B. Runtime
C. Source code build time
D. Doesn’t apply to pointer types
Solution: The pointer or reference types are known at compile time for the upcasting of an object. This is because the addresses must be known for casting the derived class to base class object.

You Have Score    /10