Explore topic-wise MCQs in Object Oriented Programming.

This section includes 8 Mcqs, each offering curated multiple-choice questions to sharpen your Object Oriented Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

Which is the proper syntax of dynamic_cast?a) dynamic_cast(object)b) dynamic_cast new (object)c) dynamic_cast(object)d) dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?

A. dynamic_cast(object)b) dynamic_cast new (object)c) dynamic_cast(object)d) dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?a) Because inheritance follows has-a relationship
B. dynamic_cast new (object)c) dynamic_cast(object)d) dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?a) Because inheritance follows has-a relationshipb) Because inheritance follows is-a relationship
C. dynamic_cast(object)d) dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?a) Because inheritance follows has-a relationshipb) Because inheritance follows is-a relationshipc) Because inheritance doesn’t follow any relationship
D. dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?a) Because inheritance follows has-a relationshipb) Because inheritance follows is-a relationshipc) Because inheritance doesn’t follow any relationshipd) Because inheritance is not involved in castingAnswer: bExplanation: The downcasting is possible because the classes in inheritance follow is-a relationship. Hence the derived class is a base class. Which in turn make the downcasting possible.Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | PinterestYoutube | LinkedIn | Instagram | Facebook | Twitter | Pinterest« Prev - Object Oriented Programming using C++ Questions and Answers – Upcasting» Next - Object Oriented Programming using C++ Questions and Answers – New Operator
Answer» D. dynamic_cast(object)Answer: cExplanation: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.9. Which is the exception handler for the exceptions of downcasting?a) CastExceptionb) ClassCastingExeptionc) ClassCastingd) ClassCastExceptionAnswer: dExplanation: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.advertisement/**/ var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd("90f55663-effd-4105-b1e7-29d86b526544"); });/**/10. How to prevent the ClassCastExceptions?a) By using instanceofb) By using is-a checkc) By using arrow operator with check functiond) By checking type of conversionAnswer: aExplanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.11. Java supports direct downcasting.a) Trueb) FalseAnswer: bExplanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.12. Which way the downcasting is possible with respect to inheritance?a) Upward the inheritance orderb) Downward the inheritance orderc) Either upward or downward the inheritance orderd) Order of inheritance doesn’t matterAnswer: bExplanation: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.13. What happens when downcasting is done but not explicitly defined in syntax?a) Compile time errorb) Runtime errorc) Code write time errord) Conversion errorAnswer: aExplanation: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.14. When is the downcasting used?a) To separate inherited class from base classb) To write a more complex codec) To compare two objectsd) To disable one class in inheritanceAnswer: cExplanation: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.15. Why is downcasting possible in any language?a) Because inheritance follows has-a relationshipb) Because inheritance follows is-a relationshipc) Because inheritance doesn’t follow any relationshipd) Because inheritance is not involved in castingAnswer: bExplanation: The downcasting is possible because the classes in inheritance follow is-a relationship. Hence the derived class is a base class. Which in turn make the downcasting possible.Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | PinterestYoutube | LinkedIn | Instagram | Facebook | Twitter | Pinterest« Prev - Object Oriented Programming using C++ Questions and Answers – Upcasting» Next - Object Oriented Programming using C++ Questions and Answers – New Operator
2.

If dynamic_cast fails, which value is returned?

A. void
B. null
C. void pointer
D. null pointer
Answer» E.
3.

What does dynamic_cast return after successful type casting?

A. Address of object which is converted
B. Address of object that is used for conversion
C. Address of object that is mentioned in the syntax
D. Doesn’t return any address
Answer» B. Address of object that is used for conversion
4.

What should be used for safe downcast?

A. Static cast
B. Dynamic cast
C. Manual cast
D. Implicit cast
Answer» C. Manual cast
5.

Downcasting ____________________

A. Can result in unexpected results
B. Can’t result in unexpected result
C. Can result only in out of memory error
D. Can’t result in any error
Answer» B. Can’t result in unexpected result
6.

Downcasting is _______________________

A. Always safe
B. Never safe
C. Safe sometimes
D. Safe, depending on code
Answer» C. Safe sometimes
7.

Which among the following is a mandatory condition for downcasting?

A. It must not be done explicitly
B. It must be done implicitly
C. It must be done explicitly
D. It can’t be done explicitly
Answer» D. It can’t be done explicitly
8.

What is downcasting?

A. Casting subtype to supertype
B. Casting supertype to subtype
C. Casting subtype to supertype and vice versa
D. Casting anytype to any other type
Answer» C. Casting subtype to supertype and vice versa