This content has been marked as final. Show 3 replies
Its the other way around, you can't use non-static stuff in a static method.
964980 wrote:You read somewhere (don't know where) that non-static member variable can only be used by a non-static method. A static member variable belongs to the class, i.e. all objects of the class.
I read somewhere(don't know where) that static variable can only be used by a static method. But in the sample code below even a non-static function is able to use the static variable.
A non-static member variable belongs to a specific object of a class and therefore cannot be used in a static method, which, by definition, is not associated with any object in particular.
Edited by: baftos on May 15, 2013 5:27 AM
I read somewhere(don't know where) that static variable can only be used by a static method.No you didn't. You misunderstood, or you made it up, or you got it back to front. You've proven that this imaginary statement is incorrect. Not a real question.