BlackFriday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

SAP Exam C_ABAPD_2309 Topic 1 Question 10 Discussion

Actual exam question for SAP's C_ABAPD_2309 exam
Question #: 10
Topic #: 1
[All C_ABAPD_2309 Questions]

Exhibit:

With Icl_super being superclass for Icl_subl and Icl_sub2 and with methods subl_methl and sub2_methl being subclass-specific methods of Id_subl or Icl_sub2, respectivel. What will happen when executing these casts? Note:

There are 2 correct answers to this question

Show Suggested Answer Hide Answer
Suggested Answer: A, D

The following are the explanations for each statement:

A: This statement is correct. go_subl = CAST #(go_super) will not work. This is because go_subl is a data object of type REF TO cl_subl, which is a reference to the subclass cl_subl. go_super is a data object of type REF TO cl_super, which is a reference to the superclass cl_super. The CAST operator is used to perform a downcast or an upcast of a reference variable to another reference variable of a compatible type. A downcast is a conversion from a more general type to a more specific type, while an upcast is a conversion from a more specific type to a more general type. In this case, the CAST operator is trying to perform a downcast from go_super to go_subl, but this is not possible, as go_super is not pointing to an instance of cl_subl, but to an instance of cl_super.Therefore, the CAST operator will raise an exception CX_SY_MOVE_CAST_ERROR at runtime12

B: This statement is incorrect. go_sub2 = CAST #(go_super) will work. go_subl = CAST #(go_super) will not work. This is because go_sub2 is a data object of type REF TO cl_sub2, which is a reference to the subclass cl_sub2. go_super is a data object of type REF TO cl_super, which is a reference to the superclass cl_super. The CAST operator is used to perform a downcast or an upcast of a reference variable to another reference variable of a compatible type. A downcast is a conversion from a more general type to a more specific type, while an upcast is a conversion from a more specific type to a more general type. In this case, the CAST operator is trying to perform a downcast from go_super to go_sub2, and this is possible, as go_super is pointing to an instance of cl_sub2, which is a subclass of cl_super. Therefore, the CAST operator will assign the reference of go_super to go_sub2 without raising an exception.However, the CAST operator will not work for go_subl, as explained in statement A12

C: This statement is incorrect. go_sub2 = CAST #(go_super) will work. go_sub2->sub2_meth1(...) will not work. This is because go_sub2 is a data object of type REF TO cl_sub2, which is a reference to the subclass cl_sub2. go_super is a data object of type REF TO cl_super, which is a reference to the superclass cl_super. The CAST operator is used to perform a downcast or an upcast of a reference variable to another reference variable of a compatible type. A downcast is a conversion from a more general type to a more specific type, while an upcast is a conversion from a more specific type to a more general type. In this case, the CAST operator is trying to perform a downcast from go_super to go_sub2, and this is possible, as go_super is pointing to an instance of cl_sub2, which is a subclass of cl_super. Therefore, the CAST operator will assign the reference of go_super to go_sub2 without raising an exception. However, the method call go_sub2->sub2_meth1(...) will not work, as sub2_meth1 is a subclass-specific method of cl_sub2, which is not inherited by cl_super.Therefore, the method call will raise an exception CX_SY_DYN_CALL_ILLEGAL_METHOD at runtime123

D: This statement is correct. go_subl->subl_meth1(...) will work. This is because go_subl is a data object of type REF TO cl_subl, which is a reference to the subclass cl_subl. subl_meth1 is a subclass-specific method of cl_subl, which is not inherited by cl_super.Therefore, the method call go_subl->subl_meth1(...) will work, as go_subl is pointing to an instance of cl_subl, which has the method subl_meth1123


Contribute your Thoughts:

Tricia
5 months ago
I am considering option D, it also makes sense to me.
upvoted 0 times
...
Marget
5 months ago
I agree with Cristal, option B seems like the right choice.
upvoted 0 times
...
Glory
5 months ago
I am not sure, but I believe option C might be correct.
upvoted 0 times
...
Cristal
5 months ago
I think the correct answer is B.
upvoted 0 times
...
Reuben
5 months ago
I think option C is correct because it mentions casting from superclass to subclass will not work, which makes sense.
upvoted 0 times
...
Lorriane
5 months ago
I'm not sure about option B, but option A seems more reasonable to me.
upvoted 0 times
...
Delsie
5 months ago
But what about option B? It says casting from superclass to subclass will work.
upvoted 0 times
...
Harrison
6 months ago
This question is like a game of ABAP chess. I bet the exam writers are having a field day with this one!
upvoted 0 times
...
Helene
6 months ago
I agree with Lorriane, option A seems logical.
upvoted 0 times
...
Yolando
6 months ago
Samantha
upvoted 0 times
King
5 months ago
D) go_subl->subl_meth !(...)* w'll work.
upvoted 0 times
...
King
5 months ago
C) go_sub2 = CAST #(go_super). will not work. ] go sub2->sub2 meth 1(...). will work
upvoted 0 times
...
King
5 months ago
B) go_sub2 = CAST # go super), will work. go_subl CAST #go_super), will work
upvoted 0 times
...
...
Lorriane
6 months ago
I think option A is correct because casting from superclass to subclass will not work.
upvoted 0 times
...

Save Cancel