‎2007 May 29 12:48 PM
hi guru
what is difference between overloading & overriding
regards
subhasis.
‎2007 May 29 12:52 PM
) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.
d) Overloading must have different method signatures whereas overriding must have same signature.
‎2007 May 29 12:52 PM
) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.
d) Overloading must have different method signatures whereas overriding must have same signature.
‎2007 May 29 12:58 PM
Hello Subhasish,
CLASS zl_lcl_vehicle DEFINITION.
PUBLIC SECTION.
<b>* Signature of method</b>
METHODS: set_make
IMPORTING value(im_make) TYPE string " Pass by value
im_model TYPE string," Pass by reference
ENDCLASS. "zl_lcl_vehicle DEFINITION
CLASS zl_lcl_vehicle IMPLEMENTATION.
<b>* Implementation of method.</b>
METHOD set_make.
IF im_make IS NOT INITIAL
AND im_model IS NOT INITIAL.
gv_make = im_make.
gv_model = im_model.
ENDIF.
ENDMETHOD. "set_make
ENDCLASS. "zl_lcl_vehicle
<u><b>Overloading</b></u> means changing signature as well as implementation of a method.
<u><b>Overriding</b></u> is changing only implementation of method with signature unchanged.
From ABAP perspective, <b>only the CONSTRUCTOR method can be overloaded</b> in a subclass i.e both the signature and implementation can be adapted in subclass.
Any other method can't be overloaded. It can only be redefined/overridden i.e implementation changed with signature unchanged.
Award points if found useful.
Regards
Indrajit.
‎2007 Aug 08 6:23 PM
hi..
I think the definition of overloading is <u>having a different set of parameters for the same method</u>. In other languages, multiple methods are allowed to be created with the same name but with different parameters. In ABAP Objects, this is not allowed. However, the same effect can be recreated by ABAP Objects via the keyword OPTIONAL.
Overriding on the other hand basically is <u>redefining a method in a subclass previously defined in its superclass</u>. In ABAP Objects, only the implementation part is allowed to be overridden.
So, I think its fair to say, in ABAP Objects, all methods can be (to some degree) be overridden and overloaded.
Constructors, can be overloaded and overridden also. Constructors are a bit special though in terms of inheritance. You can redefine both the definition and the implementation. However, (this bothers me) you must call super->constructor inside the overriding constructor.