Inheritance
Inheritance lets one class reuse another class.
The child gets the parent's tools, then can add more.
Think of Animal as a base toy set.
Dog is a special Animal pack with an extra bark sound.
Basic inheritance
Put the parent class name in parentheses after the child name.
The child can use parent methods, or replace them.
Using super()
super() calls the parent version.
Common inside __init__ so the parent can set shared fields first.
Then the child adds its own fields.
Overriding methods
Define the same method name on the child.
That replaces the parent behavior for child objects.
Extend without erasing
Call super inside the child method.
Keep the parent behavior, then add an extra step.
isinstance checks
Use isinstance() to ask if an object belongs to a class.
A child object also counts as an instance of the parent.
When inheritance fits
Use it for a clear is-a link: Dog is an Animal
Share common behavior in the parent
Override only what must change
If you only need to use another object, keep it as a part instead
Tip: Inherit for shared behavior. Override with care. Use super() when you still need the parent steps.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.