FAQ: Inheritance and Polymorphism - Child Classes in Arrays and ArrayLists

When I now use a loop to run a method on all parts of the array, will an overwriten method from the child class be applied?

Yes, if it is overwritten in each child class of each child instance in the array, then yes: the method for that child instance will behave the way you have overwritten it in its subclass (so long as you don’t change the method signature ie its name, return type and params). If it isn’t overwritten, then it will behave as it was originally defined in and inherited from its parent class.

my issue with these lessons is they often throw something in without any explanation that we have not seen before. it really is a shame because have to go to forums and spend so much time to figure it out.

Monster dracula, wolfman, zombie1;

Had no idea what this line was doing as we never covered or created instances like that. Also using Monster{} in that way didn’t get the explanation it deserved. I like this course but there are holes here and there like this that really slow things down.

1 Like