‎2008 Mar 31 8:55 AM
Hi all,
Can any one tell me wat is Method overloading n overriding
‎2008 Mar 31 9:00 AM
Methods overloading
Methods overloading is creating different methods with same name but with different parameters.
Method Overriding
Method overriding is creating a method in the derived class that has the same name arguments as in the superclass. This new method hides the superclass method.
‎2008 Mar 31 9:00 AM
hi,
ABAP Objects Concepts
| Classical Object Model (like C++, Java, )
l Attributes, methods and events (instance and classlevel)
l Single inheritance for classes
l Interfaces, nested interfaces
l Integration with GUI and persistence
l No method overloading
l Garbage collection
l Hybrid language
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.
If you do not add any new declarations to the subclass, it contains the same components as the superclass. However, only the public and protected components of the superclass are visible in the subclass. Although the private components of the superclass exist in the subclass, they are not visible. 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. Methods that a subclass inherits from a superclass use the private attributes of the superclass, and not any private components of the subclass with the same names.
If the superclass does not have a private visibility section, the subclass is an exact replica of the superclass. However, you can add new components to the subclass. This allows you to turn the subclass into a specialized version of the superclass. If a subclass is itself the superclass of further classes, you introduce a new level of specialization.
A class can have more than one direct subclass, but it may only have one direct superclass. This is called single inheritance. When subclasses inherit from superclasses and the superclass is itself the subclass of another class, all of the classes involved form an inheritance tree, whose degree of specialization increases with each new hierarchical level you add. Conversely, the classes become more generalized until you reach the root node of the inheritance tree. The root node of all inheritance trees in ABAP Objects is the predefined empty class OBJECT. This is the most generalized class possible, since it contains neither attributes nor methods. When you define a new class, you do not have to specify it explicitly as the superclass - the relationship is always implicitly defined. Within an inheritance tree, two adjacent nodes are the direct superclass or direct subclass of one another. Other related nodes are referred to as superclasses and subclasses. The component declarations in a subclass are distributed across all levels of the inheritance tree.
Redefining Methods
All subclasses contain the components of all classes between themselves and the root node in an inheritance tree. The visibility of a component cannot be changed. However, you can use the REDEFINITION addition in the METHODSstatement to redefine an inherited public or protected instance method in a subclass and make its function more specialized. When you redefine a method, you cannot change its interface. The method retains the same name and interface, but has a new implementation.
The method declaration and implementation in the superclass is not affected when you redefine the method in a subclass. The implementation of the redefinition in the subclass obscures the original implementation in the superclass.
Any reference that points to an object of the subclass uses the redefined method, even if the reference was defined with reference to the superclass. This particularly applies to the self-reference me->. If, for example, a superclass method m1 contains a call CALL METHOD [me->]m2, and m2 is redefined in a subclass, calling m1 from an instance of the subclass will cause the original method m2 to be called, and calling m1 from an instance of the subclass will cause the redefined method m2 to be called.
Within a redefine method, you can use the pseudoreference super-> to access the obscured method. This enables you to use the existing function of the method in the superclass without having to recode it in the subclass.
Hope this helps, Do reward.
‎2020 Sep 22 8:53 AM
Method Overloading:
Method Overriding:
‎2024 Dec 17 3:34 PM
As others stated, ABAP has no "real" overloading.
But we noticed there's some special case of overloading when the extended syntax check told us that >>Method "LOG" overwrites the predefined function "LOG"<<.
We were puzzled at first but as you see could figure it out.
See https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-obscuring-built-in-functi... for another example.