Hi By declaring a method static , the method would execute without constructing a instance of the corresponding class. So when your main starts executing, even the static test would be executed, irrespective you create an instnace Test t = new Test(); But for the non static methods , you have to create an instance to invoke methods in the class. As far as overloading goes, the methods must have different signatures, means return type and number of arguments. so "static" does not come into picture if this was a overloading question. Praveen
Thanks praveen, but I read somewhere that static methods can be overloaded only by static methods. I know, If a method differs with arguments AND/OR return types, it is overloading. My question is, is this overloading? If yes, is it possible to overload staic method with instance method? Thanks [ June 14, 2002: Message edited by: Thiru Thangavelu ]
I think you read "Static methods cannot be overriden by non static methods", overload allow you to have methods with the same name, as long the parameters differ in type and number.
...I know, If a method differs with arguments AND/OR return types, it is overloading...
Return type is not a part of method's signature. Overloading method can have different return type. Only arguments types and order are important.
...If yes, is it possible to overload staic method with instance method?...
The point here is to understand a big difference between overloading and overriding methods. Overloaded methods are completely independent from the compiler's point of view. The same name is just for programmer's fun. But compiler determine which method to call not by name only, but by method's signature. This is method's name and argument types (order, count). Argument names are not important - there's no more names when you make a method call. Return type is not important due to possible implicit type changes. That is - if you have two mathods declarations: int foo( int a, int b ); float foo( int a, int ? ); And late smth. like this: double j = foo( 10, 15 ); No way to decide which one is to call 8( So, yes, you can have to completely separated (from compiler's point of view) methods, and one of them is static while another one is not. [ June 15, 2002: Message edited by: Igor Romanov ]
Hi Thiru Thangavelu, Your question: "My question is, is this overloading? If yes, is it possible to overload staic method with instance method?" The answer is very simple. If two methods have two different signitures, why do we have worry about which one is static and which one is not? They have nothing to do with each other except that they have the same method name.
It is merely an overloaded method which doesn't care any modifier including static as long as the argument list is different and method name is same. Thanks for all of you, I understood the concept.
Post by:autobot
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards