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

Abap oop's

Former Member
0 Likes
553

Hi all,

*********************************************************

REPORT zinheritance.

----


  • CLASS counter DEFINITION

----


CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PROTECTED SECTION .

DATA count TYPE i.

ENDCLASS. "counter DEFINITION

----


  • CLASS counter IMPLEMENTATION

----


CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD. "set

METHOD increment.

ADD 1 TO count.

ENDMETHOD. "increment

METHOD get.

get_value = count.

ENDMETHOD. "get

ENDCLASS. "counter IMPLEMENTATION

----


  • CLASS counter_ten DEFINITION

----


CLASS counter_ten DEFINITION INHERITING FROM counter.

PUBLIC SECTION.

METHODS increment REDEFINITION .

DATA count_ten.

ENDCLASS. "counter_ten DEFINITION

----


  • CLASS counter_ten IMPLEMENTATION

----


*

----


CLASS counter_ten IMPLEMENTATION.

METHOD increment.

DATA modulo TYPE i.

CALL METHOD super->increment .

WRITE / count.

modulo = count MOD 10.

IF modulo = 0.

count_ten = count_ten + 1.

WRITE count_ten.

ENDIF.

ENDMETHOD. "increment

ENDCLASS. "counter_ten IMPLEMENTATION

DATA: count TYPE REF TO counter,

number TYPE i VALUE 5.

START-OF-SELECTION.

<b>CREATE OBJECT count TYPE counter_ten .</b>

CALL METHOD count->set

EXPORTING

set_value = number.

DO 20 TIMES.

CALL METHOD count->increment.

ENDDO.

********************************************************

In this program there is a class called counter and another class ciunter_ten inherited from the counter class.

In this statement <b>DATA: count TYPE REF TO counter.</b> we are defining a reference to the class Counter.

But when he is creating the object he adds an addition type counter_ten. It is in bolded form.Can any one please explain me what does it mean exactly ?

Regards,

Varun.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
515

By this UR creating an Instance for the class thru

which U can refer to the object

(I mean call the methods of the class. .)

Hi all,

*********************************************************

REPORT zinheritance.

----


  • CLASS counter DEFINITION

----


CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PROTECTED SECTION .

DATA count TYPE i.

ENDCLASS. "counter DEFINITION

----


  • CLASS counter IMPLEMENTATION

----


CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD. "set

METHOD increment.

ADD 1 TO count.

ENDMETHOD. "increment

METHOD get.

get_value = count.

ENDMETHOD. "get

ENDCLASS. "counter IMPLEMENTATION

----


  • CLASS counter_ten DEFINITION

----


CLASS counter_ten DEFINITION INHERITING FROM counter.

PUBLIC SECTION.

METHODS increment REDEFINITION .

DATA count_ten.

ENDCLASS. "counter_ten DEFINITION

----


  • CLASS counter_ten IMPLEMENTATION

----


*

----


CLASS counter_ten IMPLEMENTATION.

METHOD increment.

DATA modulo TYPE i.

CALL METHOD super->increment .

WRITE / count.

modulo = count MOD 10.

IF modulo = 0.

count_ten = count_ten + 1.

WRITE count_ten.

ENDIF.

ENDMETHOD. "increment

ENDCLASS. "counter_ten IMPLEMENTATION

DATA: count TYPE REF TO counter,

number TYPE i VALUE 5.

START-OF-SELECTION.

<b>CREATE OBJECT count TYPE counter_ten .</b>

CALL METHOD count->set

EXPORTING

set_value = number.

DO 20 TIMES.

CALL METHOD count->increment.

ENDDO.

********************************************************

In this program there is a class called counter and another class ciunter_ten inherited from the counter class.

In this statement <b>DATA: count TYPE REF TO counter.</b> we are defining a reference to the class Counter.

But when he is creating the object he adds an addition type counter_ten. It is in bolded form.Can any one please explain me what does it mean exactly ?

Regards,

Varun.

2 REPLIES 2
Read only

Former Member
0 Likes
515

Hi

because you have defined your data as CLASS COUNTER, not COUNTER_TEN and you want your object is like CLASS COUNTER_TEN.

You can also write:

DATA: count TYPE REF TO counter_ten.

CREATE OBJECT COUNT.

Max

Read only

Former Member
0 Likes
516

By this UR creating an Instance for the class thru

which U can refer to the object

(I mean call the methods of the class. .)