2007 Jul 05 7:48 AM
can any explain exactly multiple inheritance,multilevel inheritance regarding classes with an example in detail.its urgent please.
2007 Jul 06 8:58 AM
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.
2007 Jul 05 9:13 AM
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...
2007 Jul 06 8:58 AM
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
2007 Jul 06 11:30 AM
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>
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |