# Parent function not using overwritten array from child

**URL:** <https://discourse.processing.org/t/parent-function-not-using-overwritten-array-from-child/22796>\
**Category:** Beginners\
**Created:** [July 23, 2020, 1:43pm UTC](https://discourse.processing.org/t/parent-function-not-using-overwritten-array-from-child/22796 "2020-07-23T13:43:30Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 23, 2020, 3:26pm UTC](https://discourse.processing.org/t/parent-function-not-using-overwritten-array-from-child/22796/3 "2020-07-23T15:26:41Z")

</div>

> [@NikolafTheGreat](#):
>
> I then overwrite the array in a child class and run the parent function from the child class.

You’re not overriding but overshadowing the parent’s class field named _array_ inside each of its child classes!

Overriding is for non-static methods only. Other types of class members become overshadowed instead.

So when subclassing take extra care not to accidentally re-declare inherited fields and static methods.

If you need so instead assign a value w/o re-declaring them.

```auto
// https://Discourse.Processing.org/t/
// parent-function-not-using-overwritten-array-from-child/22796/3

// GoToLoop (2020/Jul/23)

final Parent[] children = { new Child1(), new Child2(), new Child3() };

void setup() {
  printArray(children);
  println();
  for (final Parent child : children) println(child.isArrayTrue(4));
  exit();
}

abstract class Parent {
  boolean[] array;

  boolean isArrayTrue(final int index) {
    return array[index];
  }

  @Override String toString() {
    return java.util.Arrays.toString(array);
  }
}

class Child1 extends Parent {
  {
    array = new boolean[] { true, true, true, true, true, true, true };
  }
}

class Child2 extends Parent {
  {
    array = new boolean[] { false, true, false, true, false, true, false };
  }
}

class Child3 extends Parent {
  {
    array = new boolean[] { false, true, true, false, true, true, false };
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/parent-function-not-using-overwritten-array-from-child/22796)._
