Concept of super and final in ABAP Objects
Page 1 of 1
Concept of super and final in ABAP Objects
Super As we have seen in method redefinition how the system manages the uniqueness of the method name ,it has been also shown which method definition is called when the method is called from subclass or superclass. But what if we want to call the method implementation of the superclass from the subclass.
We can do this by using the ABAP key word super, super is a reference to the super class and with this reference we can call the method implementation in the super class.
- Code:
CLASS father DEFINITION.
PUBLIC SECTION.
METHODS: my_method.
ENDCLASS.
CLASS father IMPLEMENTATION.
METHOD my_method.
Write:/ ‘ this is father method’.
ENDMETHOD.
ENDCLASS.
CLASS son DEFINITION INHERITING FROM father.
PUBLIC SECTION.
METHODS:my_method REDEFINITION,
Call_my_method.
ENDCLASS.
CLASS son IMPLEMENTATION.
METHOD my_method.
Write:/ ‘father method redefined in son’.
ENDMETHOD.
METHOD call_my_method.
Call super->my_method. “ the method definition of father will be called
ENDMETHOD.
ENDCLASS.
Final
We have seen that any class can be inherited by any other class ,but suppose we want to prevent a class from being inherited then what do we do??
We can do this by adding the key word final with class. Any class that is declared bas final cannot be inheritated ,or in other words final puts an end to the inheritance tree.
Similarly if we want to put a stop to any particular method ,from being inherited we can do it by declaring as final. A point to note a final method cannot be redefined in the subclass.
- Code:
CLASS test DEFINITION FINAL. “ this class cannot be inherited
ENDCLASS.
CLASS test IMPLEMENTATION.
ENDCLASS.
Uma_ABAP- Posts : 56
Join date : 2012-03-31
Similar topics
» Accessibility of components by use of super in ABAP Objects
» Creating multiple Objects in ABAP Objects
» Difference between Procedural ABAP and ABAP Objects
» What is ABAP Objects?
» Advantages of ABAP Objects?
» Creating multiple Objects in ABAP Objects
» Difference between Procedural ABAP and ABAP Objects
» What is ABAP Objects?
» Advantages of ABAP Objects?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP