I have a class A
, where A
extends in B
and C
. I have an instance counter in A
.
public Class A {
...
private int nInstancias = 0;
...
public A(){
nInstancias+=1;
...
}
...
public int getnInstancias() {
return nInstancias;
}
...
}
However, whenever I print nInstancias
with its getNInstancias
, it always returns 0.
What am I doing wrong and how can I increase n Instances always instantiate A
or any subclass of A
?
Is it also necessary to change the nInstances in the subclass constructor?