English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

When the same data needs to be accessible between multiple instances of a class.

class Salesman { public static int numOfSalesmen; public Salesman() { ... numOfSalesmen++; ... } ... }

Salesman a;
Salesman b;
Salesman c;

a.numOfSalesmen, b.numOfSalesmen, c.numOfSalesmen, and Salesman.numOfSalesmen are all 3 now

2007-03-19 02:15:47 · answer #1 · answered by Anonymous · 0 0

Oh, pretty good question...

Ummm, Here's my poor opinion...

when you want to know how many instants of that class have been created... you can solve it by increasing static datamember from zero... But it's very rare, i think...

Oh yeah...

when you want to know the property or state of one class without creating the object of that one... (here can be changed during the run-time...)
then, you can achieve it by using static data-member...

anyhow, one thing clear is that we can use the static-data-member without creating the object of that one(such as class::membername) ...(because it's not belonged to any object of that class and it is created and initialized when the program is loaded on the RAM... )

thank you reading my poor suggestions...
if you have further opinion or have something not clear, then feel free to call me... cruisernk@yahoo.com

2007-03-19 10:46:39 · answer #2 · answered by QuizBox 2 · 0 0

fedest.com, questions and answers