In each subclass declare a static variable counter.
Increment it in the constructor itself
for e.g
class Cylinder extends Solids{
static int counter1;
Cylinder(){
counter1=counter1+1;
}