Inheritance (OOP) (OCR A-Level Computer Science): Flashcards

📚Flashcards
Inheritance (OOP)
Sign up to keep revising.Create a free account to study more flashcards and track your progress.

Practise the cards

12 cards from this deck

Show

Inheritance in OOP

A new class inherits attributes & methods from existing class

Main purpose of inheritance

Code reuse & hierarchical relationships between classes

Parent/superclass/base class

Existing class from which attributes & methods are inherited

Child/subclass/derived class

Inherits from parent, can have own unique attributes/methods

Code reuse in inheritance

Child uses parent's attributes/methods without rewriting code

Method overriding

Child provides new implementation of parent's method

Purpose of super()

Allows child to access methods/attributes from parent class

Establish inheritance in Python

Pass parent class as parameter to child class

Inheritance benefit: reusability

Shared behaviour in parent reused by all child classes

Inheritance benefit: extensibility

Child classes extend/customise behaviours easily

Inheritance benefit: organisation

Class hierarchies mirror real-world relationships clearly

Common mistake with super()

Forgetting super() leads to incomplete initialisation

Join 100,000+ A-Level students studying Flashcards with us.

Select your subjects, and get access to A+ resources today.