2a. Understanding Inheritance Flashcards
1
Q
What does inheritance do?
A
Inheritance defines a way for a given class to inherit attributes and methods from one or more base classes.
2
Q
Why does inheritance make easy?
A
Inheritance makes it easy to centralise common functionality and data in one place instead of having it spread out and duplicated across multiple classes.
3
Q
What syntax does a class use to inherit another?
A
The name of the class to be inherited in parentheses as a postfix.
eg. class Child(Parent):
4
Q
How does a subclass access its parent’s attributes and methods?
A
By using a dot notation after calling the super function.
eg. super().attribute