KIO
Kreative Ideen online
Static variables

Static variables

A static variables value is the same for aALL instances of the class…
The static duckCount variable is initialized ONLY when the class is first loaded, NOT each time a new instance is made.

[php] publi class DUCK { private int size; /** /* The static duckCount variable is initializes ONLY /* when the class is first loaded, NOT each time a new /* instance is made **/ private static int duckCount = 0; public Duck(){ /** /* Now it will keep /* incrementing each time /* the Duck constructor runs, /* because duckCount is static /* and won’t be reset to 0 duckCount++; } public void setsSize(int a){ size = a; } public int getSize(){ return size; } } [/php]

Leave a Reply

Your email address will not be published. Required fields are marked *