Author | Topic: Can u overload static methods with non static ones?? |
Nalini Mistry ranch hand |
posted May 06, 2000 07:29 AM
We know that static methods cannot be overridden with non static methods and vice versa. but what about overloading?? can i have a static method with one sign, and a nonstatic method with the same name, diff sign??
|
satya5 ranch hand |
posted May 06, 2000 11:56 AM
Nalini: The answer to your is yes and no. Let me explain. In a class we know static methods (variables) belong Now coming to the question: code:
The above code will compile and run. With this code my answer Coming to the NO part of my answer, I don't mean to contradict Also, it doesnot help even if I declare the overloading So, my final answer is: Can you overload a static method ? Can you invoke an overloaded static method? Hope this helps. - satya
|
sree ranch hand |
posted May 06, 2000 02:02 PM
Satya, I tried your program by uncommenting the line you commented out and it's working fine. I don't understand why you can't call an overloaded static method. When you overload a method it will be totally a different method. IMO you can overload a static method to be non static or static and you can even call that overloaded method it works fine as long as the parameter list is different. Thanks.
|
satya5 ranch hand |
posted May 06, 2000 02:20 PM
Sree: You are absolutely right. Sorry I was wrong in my earlier post. Sorry, Sorry !!!!!!! So, in essence, Static methods can be overloaded and invoked Thanks for checking on me Sree. Regds. - satya
|
Nalini Mistry ranch hand |
posted May 07, 2000 04:38 AM
thanx a lot guys!!
|
maha anna bartender |
posted May 07, 2000 01:44 PM
Nalini, To finish up I am adding this. A overloaded method is completely new born method which just happened to have the same name of the other method. It is asthough you are defining a NEW METHOD. So this method can have any parameter/parameter type/parameters order/access level/throw any exception/can have any other sutable method modifiers. You can overload in the same class OR in the subclass also. In both cases ,still the new overloading method is a NEW BORN method and all the info said above still applicable. regds
|
Nalini Mistry ranch hand |
posted May 07, 2000 11:35 PM
Thanx MA. I think something similar has come up before with private methods and overriding. I get it now.
|
| | |