Tuesday, June 21, 2011

The difference between Static and Non-Static methods

  1. Static methods are owned by the class, while non-static methods are owned by the class instances.
  2. When passing parameter to non-static methods, an implicit "this" is passed which points to the class instance. Therefore, non-static methods can use "this" to access all those non-static members (methods).
  3. However, for static methods, "this" is not passed, so static methods have no way to access those non-static members (methods). On the other side, non-static methods can always access static members (methods).

No comments:

Post a Comment