9.10. Shared Class Members
Each object of a class has its own copy of all the instance variables of the class. However, in certain cases, all class objects should share only one copy of a particular variable. A program contains only one copy of a Shared class variable in memory, no matter how many objects of the class have been instantiated. A Shared class variable represents class-wide information—all class objects share the same piece of data. The declaration of a Shared member begins with the keyword Shared.
Let us use a video game example to explain the need for Shared class-wide data. Suppose we have a video game in which Martians attack other space creatures. A Martian tends to be brave and willing to attack other space creatures when it ...
Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.