Sunday, September 17, 2006 6:36 AM
joydipkanjilal
Static vs Non - Static Methods
This is an often misunderstood concept but an important one for learners who are new to C++/Java/C#.
A static method belongs to the class and a non-static method belongs to an object of a class. That is, a non-static method can only be called on an object of a class that it belongs to. A static method can however be called both on the class as well as an object of the class. A static method can access only static members. A non-static method can access both static and non-static members because at the time when the static method is called, the class might not be instantiated (if it is called on the class itself). In the other case, a non-static method can only be called when the class has already been instantiated. A static method is shared by all instances of the class. These are some of the basic differences. I would also like to point out an often ignored difference in this context. Whenever a method is called in C++/Java/C#, an implicit argument (the 'this' reference) is passed along with/without the other parameters. In case of a static method call, the 'this' reference is not passed as static methods belong to a class and hence do not have the 'this' reference.
About joydipkanjilal
An industry experience of over 10 years. Worked extensibly in Microsoft Technologies. Working in .Net and C# for over 5 years. Skills include,
C,C++,Java,C#,VB,VC++,ASP.Net,XML,UML,etc.
I am currently working as a Technical Architect in a reputed MNC in Hyderabad, India. I have authored a lot of articles on .NET and its related technologies at ASPALLIANCE, DEVX, ASPNETPRO, CODERSOURCE, SQL-SERVER-PERFORMANCE.COM, SSWUG, etc.
Mail ID: joydipkanjilal@yahoo.com
I blog at: http://aspadvice.com/blogs/joydip/