Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Abstract Class

Former Member
0 Likes
998

Hoe can i use a method in abstract class, in a different class

Thanks

9 REPLIES 9
Read only

Former Member
0 Likes
970

when its an interface use interface keyword

otherwise use INHERITING


CLASS class DEFINITION INHERITING FROM superclass 

regards

Read only

0 Likes
970

how can i create the object for that

Read only

0 Likes
970

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.

Read only

0 Likes
970

Abstract class is already in se24, i need to use a method from it

Read only

0 Likes
970

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.

Read only

Former Member
0 Likes
970

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.

Read only

Former Member
0 Likes
970

Hi,

By using interface or inheriting the super class.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
970

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

Read only

Former Member
0 Likes
970

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