‎2008 Jun 18 9:04 AM
Why are static methods defined in super class cant be reimplemented in sub-classes?
Any workaround for this?
Regards,
Arpit.
‎2008 Jun 18 10:36 AM
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
‎2008 Jun 18 10:32 AM
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
‎2008 Jun 18 10:36 AM
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
‎2008 Jun 19 5:01 AM
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.
‎2008 Jun 19 1:24 PM
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