When should I make a class static?

i have been learning how to program for some time now and one thing that still stumps me to this day is knowing when to make a method static or not.  I just don't get the point of instantiating a method if I can make it static!

None of my data access classes are static, but all of the classes that do things like convert time, etc, are static.  What is the general rule on this?  I just don't get it - any help you can give is greatly appreciated.

PS - Whether I make my time classes static or not, the same result is brought out...  No differences - I have not tried data access classes iwth a static class.

Thanks alot,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Say you're making an application for a College to administer it's students. Somewhere inside you'd probably have a class representing a Student, with say, a property representing the year they joined the college.

There are many students in the college, most with different start dates. You would 'instantiate a new object' based on the Student class for each one. Each of these student objects you'd create would be held in a different memory space, could be addressed seperately and have a different year of joining.

Now, let's say you need to create a set of functions to manipulate generic data in some way (like converting times). These are just libraries that you use, and they don't represent different things, so you  don't need to create a whole new version of it each time you use it - you don't need to create many instances of it.

The first type of situation is where a non-static class would be appropriate (where you need many seperate objects), the second is where a static class would be used (there is only ever one).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Basically, Static classes would apply for Utility type functionality.

For instance, if you want to verify that a Date value is Valid (let's say - any date that is after 1/1/2000 but before 1/1/2010 would be considered as valid)  This would be a candidate for a Static method

Public Class DateUtilties
     Public Shared Function isValidDate(byVal checkDate as Date) as Boolean

     End Function
End Class

or in C#

Public Class DateUtilties
     bool static isValidDate( Date checkDate)

End Class

The big difference is that with Shared (VB) or static (C#) procedures, you do NOT create an instance of the class, in order to use the shared/static procedures within the class.


Static methods can be used when the method operates only on variables passed as parameters or constant values from the class that contains it. Any method that needs to access a member variable in the containing class cannot be static.

Forced accept.

EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.