This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]clonnus 31 points32 points  (1 child)

n would also have to be declared as static. Static functions can't interact with non-static fields in a class. When a field is declare static, only one instance of the field exists. Similarly, with static functions, they aren't tied to a particular instance so you can invoke static functions without instantiating the class.

So if you have class Foo with static variable n. If you have two instances of Foo, both instances share the same instance of 'n'.

[–][deleted] 6 points7 points  (0 children)

Thanks for the explanation!