

MCQOPTIONS
Saved Bookmarks
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 | |