View Single Post
  #4 (permalink)  
Old 01-04-2008, 02:09 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Static methods
Hello bugger

CaptainMorgan's example explains how to call the static and non-static methods and not why someone would like to do that. Static methods can only access static attributes of a instanced class. For example:
You have a class called Dog with a static field called numberOfDogs. In the constructor of Dog you can increment numberOfDogs and if you override the finalize method then you can decrement numberOfDogs. This way you can track how many Dog objects that you have created thanks to the static modifier. Now, you can add static methods to the Dog class to manipulate numberOfDogs without you having to create an instance of Dog
Hope this helped.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 01-04-2008 at 03:03 PM.
Reply With Quote