Java Programming, Episode 20: Inheritance

preview_player
Показать описание
Java Programming with Michael Kölling, Episode 20: Inheritance
Рекомендации по теме
Комментарии
Автор

Thanks for the step-by-step walk-through, which shows that you always have students in mind. Wouldn't it be clearer to add an @Override above the overridden methods so that you instantly notice which methods have actually been overridden?

legymhueck
Автор

I just noticed that this code allows a Child to have another Child to its right. You can see that behavior at the 21:15 mark of the video where, by my count, 4 Person objects have two Child objects to their right. I assume this happens because the addedToWorld method is also invoked when the Child objects are added to the world, which means there is a 10% chance that another Child object will be created.


I fixed this problem by adding the if-statement if ( ! (this instanceOf Child ) )
to the start of the addedToWorld method. Is there a better way?

stevegregg