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

Method overloading n overriding

Former Member
0 Likes
12,025

Hi all,

Can any one tell me wat is Method overloading n overriding

4 REPLIES 4
Read only

Former Member
0 Likes
6,130
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.
Read only

Former Member
0 Likes
6,130

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.

Read only

prabhu_04
Explorer
6,130

Method Overloading:

  • It’s a Process of Overloading a method with different Signature that is with different Number and different types of Parameters.
  • ABAP doesn’t Support method Overloading.

Method Overriding:

  • The Process of overriding the super class method inside the subclass is called as Method Overriding.
  • In case of Local class in order to Override the super class method inside the subclass, the must redeclare the super class method by Using Redefinition Keyword.
  • A sub class can redefine only the instance public and Instance Protected methods of the super class.
  • When the subclass redefine the super class methods the subclass can’t change visibility of redefined methods.
  • Whenever a subclass redefine the super class methods its recommended to call the super class method implementations inside the subclass. This is done by using Super Keyword.
  • A super class instance public or Instance Protected method declare as final cant be redefine the subclass.
Read only

su01
Participant
0 Likes
3,612

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.