Community resourceWorksheet

OCR H446 1.2.4 OOP classes, objects, attributes, methods and constructors

Part 6 of 10 · H446 1.2.4 · Types of programming language

Object-oriented questions at H446 1.2.4 start with precise vocabulary: a class defines, an object holds its own state, and a constructor initialises a new instance from the parameters it was given. This worksheet separates those ideas and has students write coherent OCR-style class definitions.

Students will:

  • distinguish a class definition from an object and its individual state
  • recognise a constructor that follows its stated parameters rather than asking for fresh input
  • explain why updating one object leaves another instance of the same class unchanged
  • state the resulting attribute values of two separate objects after a method call
  • write an OCR-style class with private attributes, a constructor and public methods

Inside: 5 explanation cells, 1 multiple-choice question, 2 fill-in-the-blanks cells and 2 written answers. 23 marks, about 40 to 50 minutes.

Series: H446 1.2.4 · Types of programming language, part 6 of 10.

Shared by Coding PathwayVerified teacher

  • 10 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 31 Aug 2026
  • Updated 3 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

OOP foundations: classes, objects and constructors

A class is a definition. An object is one instance with its own state. A constructor initialises a newly created object; it is not the class declaration and should use the supplied parameters rather than asking for fresh input.

Blueprint and independent state

Class, objects, state and behaviourclass Sensorprivate location, readingpublic update(), getReading()defines structure and behaviourhallSensor : Sensorlocation = hall, reading = 18one independent object statelabSensor : Sensorlocation = lab, reading = 21another independent object stateThe constructor initialises each new object; it is not the class declaration itself.

An attribute stores object state. A method defines behaviour that can read or change that state. A constructor creates the required initial state. Two objects made from the same class share the structure and method definitions, but their attribute values are independent.

OCR-style worked model

class Sensor
    private location
    private reading

    public procedure new(locationIn, readingIn)
        location = locationIn
        reading = readingIn
    endprocedure

    public procedure update(newReading)
        reading = newReading
    endprocedure
endclass

hallSensor = new Sensor('hall', 18)
labSensor = new Sensor('lab', 21)
hallSensor.update(20)

Final state: hallSensor stores hall and 20; labSensor still stores lab and 21. The update call targets one object.

Fill in the blanks4 marks
A gap 1 defines structure and behaviour. An gap 2 is one instance. Stored state is held in gap 3. A gap 4 initialises a new instance.
  • class
  • object
  • attributes
  • constructor
  • loop
Multiple choice1 mark

A requirement says the constructor takes titleIn and pagesIn. Which action follows it exactly?

  • AAsk the user to input two replacement values
  • BDeclare a second class
  • CAssign the two parameter values to the object's attributes
  • DMake every attribute public
Written answer5 marks

Using the worked model, explain why updating hallSensor does not change labSensor. State the final location and reading of both objects.

Distinguish shared class definition from independent instance state.

Students type their answer here.

Apply the model independently

The remaining tasks change the context or reduce the support. Complete them without copying the worked model, then check that each explanation connects a mechanism to its consequence.

Written answer9 marks

Write coherent OCR-style pseudocode or program code for a class LibraryBook with private title, available and loanCount attributes. Its public constructor takes only titleIn, sets available to true and loanCount to 0. Add a public borrow() method that makes available false and increments loanCount.

Extract the exact requirements first. Do not add input statements or extra constructor parameters.

Students type their answer here.

Fill in the blanks4 marks
The class is the checkpoint gap 1; an object is an checkpoint gap 2. A constructor receives checkpoint gap 3 and assigns initial attribute state. Calling a method on one object changes that object's checkpoint gap 4 unless the design explicitly shares data.

Review your understanding

Before submitting, check that you can explain the main distinction in your own words, apply it in an unfamiliar context and justify each consequence rather than only naming a feature.