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

Static Methods

arpitgoyal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,560

Why are static methods defined in super class cant be reimplemented in sub-classes?

Any workaround for this?

Regards,

Arpit.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,126

Hi,

Static Methods are Class Specific and not instance specific. Therefore whether it a parent class or the child class the definition of the method cannot be different. Such methods do not need the instance of the class.

I am not able to clearly understand your requirement. I am not sure of the Work around but you can have a static method in your class that can be called. Here you can decide to call either the super class or have your own implementation.

Regards,

Saurabh

4 REPLIES 4
Read only

Former Member
0 Likes
1,126

Hi Aprit ,

So as to avoid method overidding.

Static method::::

It is a class method

Accessed using class name.method name

For using static methods, creation of instance is not necessary

A static method can only access other static data and methods. It cannot access non-static members

Now if you go implementing it in subclass this has to be done before implementing

HIDDING :

See if a sublcass defines a class method (static method) with the same signature as a class method in the super class the method in the subclass Hides the one in super-class

Hiddding a static method of a super class looks like overidiing an instance method of a superclass.When you overide an instance method we'll have the runtime polymorphism but when we do it with static method there is no runtime.

cheers

Mohinder Singh Chauhan

Read only

Former Member
0 Likes
1,127

Hi,

Static Methods are Class Specific and not instance specific. Therefore whether it a parent class or the child class the definition of the method cannot be different. Such methods do not need the instance of the class.

I am not able to clearly understand your requirement. I am not sure of the Work around but you can have a static method in your class that can be called. Here you can decide to call either the super class or have your own implementation.

Regards,

Saurabh

Read only

Former Member
0 Likes
1,126

Hi,

There is only one static component per program context. To summarize:

Static Components and Inheritance

• A class that defines a public or protected static attribute shares this attribute

with all its subclasses

• Static methods cannot be redefined

Static methods cannot be abstract because they cannot be redefined.

Read only

joerg_wegener
Product and Topic Expert
Product and Topic Expert
0 Likes
1,126

Hello,

as was described by the other posters on this thread, the fact that static methods cannot be overridden is a design decision underlying ABAP Objects.

If you want to inherit from an ABAP class in the standard, I don't have a solution. If you are free to change things because they are in your own coding, I can propose a workaround.

What you can do is to change your class so that the static methods become instance methods of a singleton. Object creation can be done in the class constructor. Now you can inherit from the singleton class and override methods normally.

Hope this helps

Joerg