You have a superclass super1 and a subclass sub1 of super1. Each class has an instance constructor and a static constructor. The first statement of your program creates an instance of sub1.
In which sequence will the constructors be executed?
A.
Class constructor of sub1 → Instance constructor of super1 → Instance constructor of sub1 → Class constructor of super1
B.
Class constructor of super1 → Class constructor of sub1 → Instance constructor of super1 → Instance constructor of sub1
C.
Instance constructor of super1 → Class constructor of super1 → Class constructor of sub1 → Instance constructor of sub1
D.
Instance constructor of sub1 → Instance constructor of super1 → Class constructor of super1 → Class constructor of sub1
Comprehensive and Detailed Explanation from Exact Extract:
Execution order when creating an instance of a subclass:
Class constructor of the superclass (super1) executes first.
Class constructor of the subclass (sub1) executes second.
Then the instance constructor of the superclass (super1) executes.
Finally, the instance constructor of the subclass (sub1) executes.
This sequence guarantees that both the static (class-level) and instance-level initializations of the superclass are complete before the subclass is constructed.
Verified Study Guide Reference: ABAP Objects Programming Guide – Class and Instance Constructor Execution Order.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit