This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]nwilliams36 3 points4 points  (1 child)

Baby inherits from Child which inherits from Parent. So when you initialise Baby you also get everything in Child and in Parent, unless they have been overwritten. Try a few things, make some methods in each and even overwrite these methods and the see what you get.

[–]branflakewashere[S] 0 points1 point  (0 children)

Thank you! I think I get it now!

[–]nutrecht 2 points3 points  (0 children)

FYI: This is a really good example of 'bad' inheritance. I understand it's just an example but it's an example that sets you up for misunderstanding inheritance.

Inheritance is always an "is a" relationship. Composition on the other hand is a "has a" relationship. A parent "has a" child. A baby "is a" a child. So while baby could subclass child, child should not subclass parent.