Posted: Fri Feb 08, 2008 4:28 pm Post subject: Статический и инстанс конструктор
Привет!
Пытаюсь разобраться с работой классов. Сделал небольшую программу с тремя классами C1, C2.
Класс C2 наследуется от C1.
Какая последовательность вызова статического и инстанс конструкторов классов C1 и С2?
Вот немного модифицированный пример из курса BC404
Quote:
The static constructor is a special static method in a class and is always named CLASS_CONSTRUCTOR. It is executed precisely once per program. The static constructor of class <classname> is called automatically before the class is first accessed, that is, before any of the following actions are executed:
Creating an instance in the class using CREATE OBJECT obj, where obj has the data type
REF TO <classname>.
Addressing a static attribute using <classname>=><an_attribute>.
Calling a static attribute using CALL METHOD <classname>=><a_classmethod>.
Registering a static event handler method using SET HANDLER <classname>=><handler_method> for obj.
Registering an event handler method for a static event in class <classname>.
The static constructor cannot be called explicitly.
Code:
CLASS lcl_airplane DEFINITION.
PUBLIC SECTION.
TYPES: name_type(25) TYPE c.
CONSTANTS: pos_1 TYPE i VALUE 30.
* Constructor
METHODS: constructor importing
im_name TYPE name_type
im_planetype TYPE saplane-planetype,
set_attributes IMPORTING
im_name TYPE name_type
im_planetype TYPE saplane-planetype,
display_attributes.
DATA: name TYPE name_type,
planetype TYPE saplane-planetype.
CLASS-DATA: n_o_airplanes TYPE i.
ENDCLASS.
*------------------------------------------------------------------*
* CLASS lcl_airplane IMPLEMENTATION *
*------------------------------------------------------------------*
CLASS lcl_airplane IMPLEMENTATION.
METHOD display_attributes.
WRITE: / 'Name of the airplane: '(001), at pos_1 name,
/ 'Plane type: '(002), at pos_1 planetype.
ENDMETHOD.
METHOD display_n_o_airplanes.
WRITE: /, / 'Total number of airplanes: '(ca1),
AT pos_1 n_o_airplanes left-justified, /.
ENDMETHOD.
ENDCLASS.
*------------------------------------------------------------------*
* CLASS lcl_cargo_airplane DEFINITION *
*------------------------------------------------------------------*
CLASS lcl_cargo_airplane DEFINITION INHERITING FROM lcl_airplane.
PUBLIC SECTION.
METHODS: constructor IMPORTING
im_name TYPE name_type
im_planetype TYPE saplane-planetype
im_cargo_max TYPE p,
display_attributes REDEFINITION.
*------------------------------------------------------------------*
* CLASS lcl_cargo_airplane IMPLEMENTATION *
*------------------------------------------------------------------*
CLASS lcl_cargo_airplane IMPLEMENTATION.
Instance Constructor of Class lcl_airplane
Static Constructor of lcl_cargo_airplane
Instance Constructor of Class lcl_airplane
Instance Constructor of Class lcl_cargo_airplane
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.