Inheritance (OOP) (OCR A-Level Computer Science): Flashcards
📚Flashcards
Practise the cards
12 cards from this deck
ShowHide
Practise the cards
12 cards from this deck
Inheritance in OOP
Inheritance in OOP
A new class inherits attributes & methods from existing class
Main purpose of inheritance
Main purpose of inheritance
Code reuse & hierarchical relationships between classes
Parent/superclass/base class
Parent/superclass/base class
Existing class from which attributes & methods are inherited
Child/subclass/derived class
Child/subclass/derived class
Inherits from parent, can have own unique attributes/methods
Code reuse in inheritance
Code reuse in inheritance
Child uses parent's attributes/methods without rewriting code
Method overriding
Method overriding
Child provides new implementation of parent's method
Purpose of super()
Purpose of super()
Allows child to access methods/attributes from parent class
Establish inheritance in Python
Establish inheritance in Python
Pass parent class as parameter to child class
Inheritance benefit: reusability
Inheritance benefit: reusability
Shared behaviour in parent reused by all child classes
Inheritance benefit: extensibility
Inheritance benefit: extensibility
Child classes extend/customise behaviours easily
Inheritance benefit: organisation
Inheritance benefit: organisation
Class hierarchies mirror real-world relationships clearly
Common mistake with super()
Common mistake with super()
Forgetting super() leads to incomplete initialisation
