Objects (OOP) (OCR A Level Computer Science)

Revision Note

Craig Godbold

Expertise

Computer Science

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);

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

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

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.