Q: 11
Refer to the exhibit.
with which predicate condition can you ensure that the CAST will work?
with which predicate condition can you ensure that the CAST will work?Options
Discussion
I'd go C. In ABAP, IS INSTANCE OF checks type compatibility before casting so that's needed here.
Option C IS INSTANCE OF is the right check. B is a trap since it checks initialization, not type compatibility for casting. Pretty sure about this based on SAP practice.
C , seen this in SAP official docs and practice tests too. IS INSTANCE OF is what checks type compatibility before casting.
C is what I'd pick here. You want to make sure the object actually matches the class before you CAST, otherwise ABAP will throw a runtime error. That's exactly what IS INSTANCE OF checks for. Official SAP guide and a good practice test both cover this scenario. If someone has a different take, let me know.
B or D. I've seen SAP practice tests push both IS NOT INITIAL and IS BOUND as checks for object refs before casting. Maybe double-check in the official guide, I know forums sometimes mix them up.
I don't think it's B here. IS NOT INITIAL is about checking if the variable has been set, not if it matches a type. For casting safely in ABAP, you need to confirm the reference is the correct class, so C (IS INSTANCE OF) is really the best match. Saw this style on a practice too. Open to other takes though.
C since IS INSTANCE OF checks if the object really is of the specific class or subclass before you use CAST. That way you avoid runtime errors from invalid types in ABAP. IS NOT INITIAL would just check if something exists, not type. I think C is safest for this scenario, unless SAP changed something I'm missing.
For this kind of CAST you need to check type compatibility, so C (IS INSTANCE OF) fits. Saw a similar question in a practice exam, IS INSTANCE OF is the usual way to avoid cast errors. Makes sense?
Be respectful. No spam.