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

urgent-oops

Former Member
0 Likes
622

can any explain exactly multiple inheritance,multilevel inheritance regarding classes with an example in detail.its urgent please.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
595

Hi Sandeep,

Multiple Inheritance is inheriting from 2 or more classes. This is not supported in ABAP, but can be simulated using interfaces.

Multilevel Inheritance is generating a kind of inheritance tree. Subclass1 inheriting from superclass, subclass2 inheriting from subclass1 and so on.

Award points if useful.

Regards

Indrajit

can any explain exactly multiple inheritance,multilevel inheritance regarding classes with an example in detail.its urgent please.

3 REPLIES 3
Read only

Former Member
0 Likes
595

Hi Sandeep,

The situation in which a class inherits from two different classes simultaneously is known as multiple inheritance, which is NOT supported in ABAP. ABAP object only have SINGLE inheritance.

Eg of Multiple Inheritance ( Not supported in ABAP)

Class: SUPER1, SUPER2.

Calss: SUB1 INHERITING FROM SUPER1 , SUPER2.

A class, which is a superclass to one class can in turn be inherited from some other class also. This is known as mutilevel inheritance which is supported in ABAP.

Eg. of Multilevel Inheritance.( SUPPORTED IN ABAP)

Class Airplane DEFINITION

PUBLIC SECTION

---

ENDCLASS

CLASS PASSENGER_PLANE DEFINITION INHERITING FROM AIRPLANE .

PUBLIC SECTION

---

ENDCLASS

CLASS JET DEFINITION INHERITING FROM PASSENGER_PLANE.

PUBLIC SECTION.

--

ENDCLASS.

THis is called as multi level inheritance.

Hope it is clear for u.. Pls reward with points if it is useful for u...

Read only

Former Member
0 Likes
596

Hi Sandeep,

Multiple Inheritance is inheriting from 2 or more classes. This is not supported in ABAP, but can be simulated using interfaces.

Multilevel Inheritance is generating a kind of inheritance tree. Subclass1 inheriting from superclass, subclass2 inheriting from subclass1 and so on.

Award points if useful.

Regards

Indrajit

Read only

Former Member
0 Likes
595

Hi Sandeep,

<b>Inheritance:</b>

Inheritance allows you to derive a new class from an existing class.You do this using the INHERITING FROM addition in the CLASS <subclass> DEFINITION INHERITING FROM <superclass>.statement. The new class <subclass> inherits all of the components of the existing class <superclass>. The new class is called the subclass of the class from which it is derived.The original class is called the superclass of the new class. Only the public and protected components of the superclass are visible in the subclass.You can declare private components in a subclass that have the same names as private components of the superclass. Each class works with its own private components.

REPORT ZTRG_OBJ2 .

----


  • 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,

  • COUNT TYPE REF TO COUNTER_TEN,

NUMBER TYPE I VALUE 5.

START-OF-SELECTION.

CREATE OBJECT count TYPE counter_ten .

*CREATE OBJECT COUNT .

CALL METHOD COUNT->SET

EXPORTING

SET_VALUE = NUMBER.

DO 20 TIMES.

CALL METHOD COUNT->INCREMENT.

ENDDO.

<b>Reward points if useful</b>