Thursday, June 01, 2006

Static methods

Static methods cannot access instance methods or instance variables:

Static methods have no such concept. If you think about it, that makes complete sense. Remember that a static method does not require an object to be invoked; normally, static methods are invoked using the ClassName.staticMethodName() syntax. Because a static method can be invoked with no object instance whatsoever, how could there be a this reference?

The rule is that static methods (like the main() method) can never access instance methods or instance variables; static methods can invoke only other static class members directly. Another way to say this is that you cannot invoke an instance method or access an instance variable without an object instance.

1 Comments:

At 3:58 PM, Blogger Unknown said...

With object instance can static method invoke other method??

 

Post a Comment

<< Home