Community resourceWorksheet
OCR H446 1.2.4 Object Oriented Programming 1
Part 2 of 6 · H446 Data Structures and OOP
This worksheet introduces object-oriented programming concepts using Python. Pupils explore classes, objects, constructors and methods through examples like books, films and library management. It is an introductory resource suitable for learners beginning to work with OOP fundamentals and simple class designs.
Shared by Chris H.Verified teacher
- 14 cells
- About 50 minutes
- CC BY-SA 4.0
- Shared 29 Jul 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Classes, objects and constructors
OCR H446 references: 1.2.4(e), 2.2.1(f) and Appendix 5d
Many programs model real or imagined things: characters in a game, tracks in a music library, sensors in a laboratory or films in a streaming catalogue. Object-oriented programming gives us a structured way to describe what each kind of thing stores and what it can do.
In this worksheet, OCR pseudocode is shown so that you can read examination questions confidently. Every executable example and programming task uses clear Python.
You should already know how variables and functions work in Python.
By the end, you should be able to:
- distinguish a class from an object
- identify attributes, methods and constructors
- read a simple OCR pseudocode class
- define, instantiate and use a class in Python
From a general design to individual objects
Imagine a streaming service that needs to store thousands of films. Every film has the same kinds of information, such as a title and age rating, but each film has its own values.
A class describes that common design. It defines:
- the attributes each object will store
- the methods each object will be able to use
An object, also called an instance, is one particular item created from the class. Hidden Figures and Dune could be two different objects made from the same Film class.
Attributes and methods
An attribute stores data belonging to one object. A Film object might store title and age_rating.
A method is a procedure or function belonging to the class. It describes behaviour involving that object's data. A label() method could combine a film's title and rating into display text.
The constructor
A constructor runs when a new object is created. Its job is to place the new object into a sensible starting state by assigning its initial attribute values.
OCR pseudocode
class Film
title
ageRating
public procedure new(givenTitle, givenRating)
title = givenTitle
ageRating = givenRating
endprocedure
public function label()
return title + " (" + ageRating + ")"
endfunction
endclass
exampleFilm = new Film("Hidden Figures", "PG")
OCR calls the constructor new. You need to understand what this pseudocode does, but you do not need to reproduce every part of its syntax from memory.
Python equivalent
class Film:
def __init__(self, title, age_rating):
self.title = title
self.age_rating = age_rating
def label(self):
return self.title + " (" + self.age_rating + ")"
example_film = Film("Hidden Figures", "PG")
In Python:
__init__is the constructor methodselfrefers to the particular object currently using the methodself.titlemeans thetitleattribute belonging to that object- calling
Film("Hidden Figures", "PG")creates the object and runs its constructor
If another Film object is created, it has its own attribute values even though it uses the same class definition.
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
def summary(self):
return self.title + " by " + self.author
first_book = Book("The Hobbit", "J. R. R. Tolkien")
second_book = Book("Noughts and Crosses", "Malorie Blackman")
print(first_book.summary())
print(second_book.summary())Blueprint used to create instances: ______. One created instance: ______. Data stored by an instance: ______. Behaviour belonging to a class: ______. Code that initialises a new instance: ______.- class
- object
- attribute
- method
- constructor
The program contains first_book = Book("The Hobbit", "J. R. R. Tolkien"). What is first_book?
- AThe constructor belonging to Book
- BAn object created from the Book class
- CAn attribute belonging to every class
- DA new class that replaces Book
Checkpoint: read a class before writing one
Return to the Book example and locate each part:
- class name:
Book - constructor:
__init__ - constructor parameters:
titleandauthor - object attributes:
self.titleandself.author - method:
summary - two separate objects:
first_bookandsecond_book
Notice that the two objects share the same method code but store different titles and authors. This is one reason classes are useful: the program defines the common structure once, then creates as many individual objects as it needs.
Guided modification
First, run the working Student class. Add one change at a time and run it again after each change. This gives you a clear point at which to find an error.
Independent class task
You will then create a Film class from an empty editor:
- Write the class header.
- Add
__init__withtitleandage_ratingparameters. - Store both values as attributes using
self. - Add the
label()method. - Create the required
example_filmobject.
Use the exact attribute, method and object names in the instructions so that the automated checks can locate your work.
class Student:
def __init__(self, name):
self.name = name
def introduce(self):
return "My name is " + self.name
student = Student("Amina")
print(student.introduce())
# Run the original program before editing it.
# Then make these changes one at a time:
# 1. Give the constructor a second parameter called subject.
# 2. Store subject as an attribute.
# 3. Make introduce() return a sentence containing name and subject.
# 4. Create Amina with the subject "Computer Science".
#
# Aim for this output:
# My name is Amina and I study Computer Science# Define a Film class.
#
# 1. Add an __init__ constructor with title and age_rating parameters.
# 2. Store both values as attributes using self.
# 3. Add a label() method that returns text in this format:
# Hidden Figures (PG)
# 4. Create example_film for Hidden Figures with a PG rating.
#
# You do not need to print the label. The checks will call the method.
Translating meaning between OCR pseudocode and Python
An examination question may describe a class in OCR pseudocode even when you will answer a programming question in Python. Translate the meaning one part at a time.
Constructor
OCR pseudocode:
public procedure new(givenName)
name = givenName
endprocedure
Readable Python:
def __init__(self, name):
self.name = name
Both versions receive a name and store it in the new object.
Creating an object
OCR pseudocode:
playerOne = new Player("Maya")
Python:
player_one = Player("Maya")
Both versions create one Player object and keep a reference to it in a variable.
For programming questions in this course, write Python. When reading OCR pseudocode, identify the class, data, behaviour and object creation first, then express the same ideas clearly in Python.
Which Python statement creates an object called player_one from the Player class?
- APlayer = player_one("Maya")
- Bclass player_one = Player
- Cplayer_one = Player("Maya")
- Dplayer_one.Player("Maya")
Explain the difference between a class and an object, and explain the purpose of a constructor.
Make three distinct points. Define the blueprint, identify the instance, then explain what happens when the instance is created.
Students type their answer here.
Independent task: model the changing state of a library book
A library book is a useful example of an object whose state changes over time. A newly added book has no borrower, so its borrower attribute starts as None. When a student borrows it, the object records the student's name. Its status() method then produces text based on the current state.
Complete and test the class in this order:
- In the constructor, store the title and set
borrowertoNone. - Make
borrow(student_name)update the current object's borrower. - In
status(), test whetherborroweris stillNone. - Return the available message in that case.
- Otherwise return the message naming the borrower.
Your class must work for both states:
- a newly created book, such as
Dune is available - a borrowed book, such as
The Hobbit is on loan to Maya
You do not need to print either result because the checks call the method directly.
# Complete the LibraryBook class.
#
# The constructor must:
# - store the title
# - set borrower to None
#
# borrow(student_name) must store the student's name.
# status() must return text in one of these formats:
# The Hobbit is available
# The Hobbit is on loan to Maya
class LibraryBook:
def __init__(self, title):
pass
def borrow(self, student_name):
pass
def status(self):
pass
book = LibraryBook("The Hobbit")
book.borrow("Maya")Write the Python statement that creates pet from a Pet class and passes the name Milo. Then state the name of the Python method that runs automatically to initialise the object.
Retrieve both parts from memory before checking the earlier examples.
Students type their answer here.