Objects (OOP) (OCR A Level Computer Science)

Revision Note

Craig Godbold

Written by: Craig Godbold

Reviewed by: James Woodhouse

Objects (OOP)

What is an Object?

  • An object is a representation of a real-world entity eg teacher, aeroplane, mobile phone, cat etc

  • A class is like a blueprint that describes the properties and behaviours of objects, while an object is a specific instance created based on that blueprint with its own unique values for the properties

  • A constructor is a special method within a class that is automatically called when an object of that class is created  (instantiated)

  • Constructors typically define the initial values of instance variables and perform any necessary setup to prepare the object for use

Example of 2 objects belonging to a class

Example of 2 objects belonging to a class

Worked Example

A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of the class definition for the ItemForSale class is shown below:

class ItemForSale
   public itemName
   public price
   public discount

Write a line of code to create an object of type ItemForSale called mushypeas that has a name of “mushy peas” and a price of £0.89   

[3]

How to answer this question:

  • Creating object with identifier

    • mushypeas =

  • creating object as type

    • ItemForSale

  • mark for parameters passed in as needed ("mushy peas",0.89) [1 mark]

Answer:

 Example answer 1 to get full marks:

mushypeas=new ItemForSale("mushy peas", 0.89)

Example answer 2 to get full marks:

ItemForSale mushypeas = ItemForSale(“mushy peas”,0.89);

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Craig Godbold

Author: Craig Godbold

Expertise: Computer Science

Craig is an experienced educator with 14 years of teaching experience in the UK, USA, and China, He has held a variety of roles in education, including Head of Faculty, IB teacher and now currently teaches A level and GCSE courses. Craig supported his students to achieve the best results the school had ever had in IB Computer Science.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.