REPORT Z_METHOD_CONSTRUCTOR. CLASS vehicle DEFINITION. PUBLIC SECTION. METHODS: accelerate IMPORTING rate type i, constructor IMPORTING i_speed TYPE i, 构造方法的定义必须使用关键字 constructor show_speed. PRIVATE SECTION. data speed TYPE i VALUE 0. ENDCLASS. CLASS vehicle IMPLEMENTATION. method accelerate. speed = speed + rate. ENDMETHOD. METHOD show_speed. write speed. ENDMETHOD. METHOD constructor. speed = i_speed. ENDMETHOD. ENDCLASS. DATA o_vehicle TYPE REF TO vehicle. START-OF-SELECTION. CREATE OBJECT o_vehicle EXPORTING i_speed = 4. "构造方法只能在第一次创建对象中直接被调用,只调用一次 CALL METHOD o_vehicle->accelerate EXPORTING rate = 2. CALL METHOD o_vehicle->accelerate EXPORTING rate = 2. CALL METHOD o_vehicle->show_speed.