#46 – There Is Only One Copy of Static Data

With instance data members of a class, there is a unique set of data that exists for each instance of the class that you create.  However, for static data members, there is always just one copy of the static data for that class.  Since the data is associated with no particular instance of the class, all references to that static data work with the same copy.

 // Create two new Person objects--two sets of instance data.
 Person p1 = new Person("Sean", 46);
 Person p2 = new Person("Fred", 28);

 // Change static data--one copy for entire Person class
 Person.Motto = "It's good to be human";

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers