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.
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;
}
}