For the total number of instances, you could have a static variable in class A. A static variable is a variable which is based on the class itself rather then the instance and is defined like so :
private static int totalInstances = 0;
And then in the constructor of class A, you would just increment that variable, and decrement it in the destructor.
You could then make an accessor for this variable
public int getTotalInstances(){
return totalInstances;
}
And you would then be able to get the total ammount of instances like so :
classA.getTotalInstances()
Make sure to make it the class name rather than the instance name.
If you wanted to keep track of the reference variables, you could create a static array of reference variables, and add the reference every time an object was created in the same manner we incremented the total instances :)