Inheritance issues
Having some issues with inheritance. I have a parent called IntArrayBag which has an ensureCapacity method which more than doubles the size of my array when I run out of space to add more ints...
I am attempting to calling it from the child, a set bag called FinalBag in an attempt to expand my local private int array of the same name (as the parents private int array). Is this possible? I am not erroring but am very aware that it is NOT getting its size increased.
From parent:
publicvoid ensureCapacity(int minimumCapacity)
{
int[ ] biggerArray;
if (data.length < minimumCapacity)
{
biggerArray =newint[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}
Child class:
publicclass FinalBagextends IntArrayBag{
privateint[ ] data;
privateint manyItems;
public FinalBag(){
finalint INITIAL_CAPACITY = 1;
manyItems = 0;
data =newint[INITIAL_CAPACITY];
}
publicvoid add(int element)
{
if (manyItems == data.length)
ensureCapacity((manyItems + 1)*2);
if (!inArray(element)){
data[manyItems] = element;
manyItems++;
}
}
private Boolean inArray(int n){
for (int i = 0; i < manyItems; i++)
if (data[i] == n)
returntrue;
returnfalse;
}
}

