Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why we can't have a static and a non-static method with same name...?
Whats the reason behind this even we use different calling mechanism for both as

class_name.static_method();

and


instance.non-static_method();
Posted

 
Share this answer
 
Hi,
A static method belongs to the class itself and a non-static (or instance) method belongs to each object that is generated from that class. If your method does something that doesn't depend on the individual characteristics of its class, make it static (it will make the program's footprint smaller). Otherwise, it should be non-static.

You can call static methods like this:
Foo.method1()
. If you try that with method2, it will fail. But this will work:
Foo bar = new Foo(1);
bar.method2();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900