You can use a static method when its outcome doesn't depend on the values of the class instance. To use the worn MSFT example, the Dinosaur class can represent various species of dinosaurs. The EatMammal() method could be static, the EatTreeLeaves() couldn't. The rulez change when you change the hierarchy. If your base class is Animal, you'll need to change EatMammal from static to virtual. Assuming that an oyster is incapable of catching a cow...
Sorry to be flippant, I had a bit too much fun with the examples. You actually have a choice between static, non-virtual and virtual. The non-virtual implementation of a method is appropriate when you are not going to derive another class from yours. The appropriate keyword to use in that case is "sealed".
|