‎2008 Jul 09 7:02 AM
Dear all Abaper experts,
I am doubt on a abap object program shown as below. It is a ABSTRACT class and method. However, during compiling, an error message is displayed "The abstract method 'WRITE_STATUS' may not be implemented". What does it mean?
REPORT ZOOP_ABSTRACT.
* Class Declaration
CLASS vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: accelerate,
write_status ABSTRACT.
PROTECTED SECTION.
DATA speed TYPE i.
ENDCLASS.
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
ENDCLASS.
* Class Implementation
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
ENDCLASS.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
CLASS ship IMPLEMENTATION.
ENDCLASS.
* Global Data
DATA: plane_ref TYPE REF TO plane,
ship_ref TYPE REF TO ship.
* Classical Processing Blocks
START-OF-SELECTION.
CREATE OBJECT: plane_ref,
ship_ref.
CALL METHOD: plane_ref->accelerate,
plane_ref->rise,
plane_ref->write_status,
plane_ref->accelerate,
plane_ref->write_status.
All answers are welcome and appreciate for the help.
‎2008 Jul 09 7:06 AM
Hi,
Abstract class -> it is not must to override all methods in abstract class. Abstract class may contain abstract methods and non abstract methods.. in this case abstract methods should be overriden and non abstract methods are need not to be overriden.
so in your case the problem is because you haven't Implemented the WRITE_STATUS method in the Subclass i.e. CLASS PLANE. or not Redefined in the Subclass.
Best Regards,
Sunil
‎2008 Jul 09 7:06 AM
Hi,
Abstract class -> it is not must to override all methods in abstract class. Abstract class may contain abstract methods and non abstract methods.. in this case abstract methods should be overriden and non abstract methods are need not to be overriden.
so in your case the problem is because you haven't Implemented the WRITE_STATUS method in the Subclass i.e. CLASS PLANE. or not Redefined in the Subclass.
Best Regards,
Sunil
‎2008 Jul 09 7:18 AM
Hi Sunil,
Really appreciate for your prompt reply.
I am a Abap newbie. I may not fully understand what you trying to explain. If you could provide or amend my code in order to make it error free would be highly appreciated.
‎2008 Jul 09 7:35 AM
Hi Sunil,
If not mistaken, I think I have implemented the write_status in the subclass Plane.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
‎2008 Jul 09 7:44 AM
Hi,
try this code I've rearranged your Class Implementation and just added the foll code;
write_status REDEFINITION in the Definition part of the Subclass.
* Class Declaration
CLASS vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: accelerate,
write_status ABSTRACT.
PROTECTED SECTION.
DATA speed TYPE i.
ENDCLASS.
* Class Implementation
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
ENDCLASS.
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise,
write_status redefinition.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS plane IMPLEMENTATION.
METHOD rise.
altitude = altitude + 1.
ENDMETHOD.
METHOD write_status.
WRITE: / 'Plane speed:', speed.
WRITE: / 'Altitude:', altitude.
ENDMETHOD.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: write_status redefinition.
ENDCLASS.
CLASS ship IMPLEMENTATION.
METHOD write_status.
WRITE: / 'In Ship Class.'.
ENDMETHOD.
ENDCLASS.
* Global Data
DATA: plane_ref TYPE REF TO plane,
ship_ref TYPE REF TO ship.
* Classical Processing Blocks
START-OF-SELECTION.
CREATE OBJECT: plane_ref,
ship_ref.
CALL METHOD: plane_ref->accelerate,
plane_ref->rise,
plane_ref->write_status,
plane_ref->accelerate,
plane_ref->write_status,
ship_ref->write_status.Best Regards,
Sunil.
‎2008 Jul 09 7:46 AM
Hi,
CLASS plane DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: rise,
write_status redefinition.
PROTECTED SECTION.
DATA altitude TYPE i.
ENDCLASS.
CLASS ship DEFINITION INHERITING FROM vehicle.
PUBLIC SECTION.
METHODS: write_status redefinition.
ENDCLASS.
Regards,
Sandeep Patel.
‎2008 Jul 09 8:05 AM