Application Development 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: 

OOPs Concept ! -> Why Static Methods can't be redefined in its subclass ?

Former Member
0 Kudos

Dear Experts ,

I had searched the SDN , but unable to find out the satisfactorily answers ..

Can anybody let me know the reason for the following Confusion in Oops Concept

Question 1: As we know , We can Inherit the Static Methods in the Sub Class , But we can't redefine it in the base class or Sub Class ?

Question 2 : Why can't Static Method be Abstract ?

Question 3 : Can a Class be Abstract or Final Both, If yes, then why ?

Thanks in Advance

Saurabh Goel

1 ACCEPTED SOLUTION

Former Member
0 Kudos

In the link on the previous post, the discussion is very valuable.

As for question 2 u2013 it arises from the issue 1. If something cannot be redefined, there is no point of it being abstract. And since static method occurs only once in the inheritance tree, no matter, if the actual code will be in the top super class or in one of the subclasses. Designers of the ABAP language could have made it possible to redefine the static methods and make use of all the features (e.g. abstract or final). It could lead to problems, but it also could be a good tool in the hands of experienced programmers. But they designed it in a particular way and that's just a language rule. "It's just the way it is".

5 REPLIES 5

Former Member
0 Kudos

This message was moderated.

matt
Active Contributor
0 Kudos

Question 1 is discussed in the updated sticky here:

Please discuss questions 2 and 3 only in this thread. I've already rejected an answer which just gave a definition of statics.

Former Member
0 Kudos

In the link on the previous post, the discussion is very valuable.

As for question 2 u2013 it arises from the issue 1. If something cannot be redefined, there is no point of it being abstract. And since static method occurs only once in the inheritance tree, no matter, if the actual code will be in the top super class or in one of the subclasses. Designers of the ABAP language could have made it possible to redefine the static methods and make use of all the features (e.g. abstract or final). It could lead to problems, but it also could be a good tool in the hands of experienced programmers. But they designed it in a particular way and that's just a language rule. "It's just the way it is".

vishesh_malik
Participant
0 Kudos

As per the above discussion two of your doubts have already been clarified so I am taking only third one.

A class cannot never be Abstract and final both coz Abstract signifies that the implementation of the class has not been defined completelyi.e. may be some methods have been defined but few methods are still missing implementation. 'Final' is used for those classes/methods which cannot be redefined means the complete implementation of the method has been defined no one can implement further logic under the same method.

If you are saying your method is Final then it cannot be overridden and Abstract implies that method implementation is yet to be defined which can only be implemented if that class/method is not 'Final'. So both the terms are contradictory.

Hope it clarifies!!!

Thanks,

Vishesh

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Saurabh,

In the book Object-oriented Programming with ABAP (ISBN 9781592292356), the author James Wood, describes "Static" components(methods, attributes) of a class as the "components which are specific to the class". Hence the declarations: CLASS-METHODS, CLASS-DATA etc.

From a semantic point of view, they shouldn't have any meaning outside of the class in which they're defined. If you think from this perspective you'll get the answers to qns. 1 & 2.

Regarding qn.3: You can define a class as FINAL & ABSTRACT. But in this case you can use only the STATIC components. Although INSTANCE components can be defined, but they cannot be used. Try to figure out the "why" ?

Hope this helps.

BR,

Suhas