‎2008 Apr 03 1:41 PM
Hoe can i use a method in abstract class, in a different class
Thanks
‎2008 Apr 03 1:43 PM
when its an interface use interface keyword
otherwise use INHERITING
CLASS class DEFINITION INHERITING FROM superclass
regards
‎2008 Apr 03 1:47 PM
‎2008 Apr 03 1:50 PM
Hi,
u cannot create object to abstract classes.so we will inherit it to some other class and create object for that.through that object we will call the abstract class methods.
see the example i have given above.
rgds,
bharat.
‎2008 Apr 03 1:56 PM
Abstract class is already in se24, i need to use a method from it
‎2008 Apr 03 2:02 PM
Hi,
say ur abstract class is ZCL_BHABSTRACT
CLASS zcl_bhabstract DEFINITION LOAD.
CLASS c2 DEFINITION INHERITING FROM zcl_bhabstract FINAL.
PUBLIC SECTION.
METHODS m2.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m2.
m1( ).
ENDMETHOD.
ENDCLASS.
DATA oref TYPE REF TO c2.
START-OF-SELECTION.
CREATE OBJECT oref.
oref->m2( ).
oref->m3( ).
CLASS zcl_bhabstract DEFINITION LOAD. statement will make the se24 class zcl_bhabstract local to the program
rgds,
bharat.
‎2008 Apr 03 1:44 PM
Hi,
see this example code
CLASS c1 DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS m3.
PROTECTED SECTION.
METHODS m1.
PRIVATE SECTION.
DATA a1 TYPE string VALUE `Attribute A1 of class C1`.
ENDCLASS.
CLASS c2 DEFINITION INHERITING FROM c1 FINAL.
PUBLIC SECTION.
METHODS m2.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
WRITE / a1.
ENDMETHOD.
METHOD m3.
WRITE / 'public method from abstract class'.
ENDMETHOD.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m2.
m1( ).
ENDMETHOD.
ENDCLASS.
DATA oref TYPE REF TO c2.
START-OF-SELECTION.
CREATE OBJECT oref.
oref->m2( ).
oref->m3( ).
rgds,
bharat.
‎2008 Apr 03 1:45 PM
Hi,
By using interface or inheriting the super class.
Thanks,
Sriram Ponna.
‎2008 Apr 03 1:46 PM
Yes U can use it.
But u have to implement all the other methods in the class. Bcz, the class is abstract class.
Regards,
Angi
‎2008 Apr 03 1:46 PM
hi Anu Chintalapudi ,
Abstract classes are majorly used when u want to substitute a part of the class functionality through your own defined implementation.
Interfaces are generally used when you dont have an exact defined implementation to any of the methods in the class..
Thats why you define an interface for a class and we will use a class to implement that.
Implementing Abstract class methods :
https://forums.sdn.sap.com/click.jspa?searchID=8998584&messageID=4078691
Hopefully it gives you some idea.
Reward if helpful
rekha