Objects (OOP) (Cambridge (CIE) A Level Computer Science): Revision Note

Exam code: 9618

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

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

Programming objects (OOP)

How do you program an object?

Pseudocode

Pseudocode for the class 'person' and instantiating two objects

Pseudocode for the class 'person' and instantiating two objects

Java

//creating the person class

public class Person {

         // creating 4 attributes for the person class

    private String firstName;

    private String surname;

    private String dateOfBirth;

    private String hobbies;

 

    // Constructor -This creates objects of the person class

    public Person(String firstName, String surname, String dateOfBirth, String hobbies) {

        this.firstName = firstName;

        this.surname = surname;

        this.dateOfBirth = dateOfBirth;

        this.hobbies = hobbies;

    }

//Creating Objects (Instances) of the person class

Person person1 = new Person("Bob", "Jones", "06/10/1981", “E Sports”);

Person person2 = new Person("Jess", "Jones", "05/04/1980", “Astronomy”);

Python

#creating the person class

class Person:

        #Constructor -This creates objects of the person class     

    def __init__(self, firstName, surname, dateOfBirth, hobbies):

        self.firstName = firstName

        self.surname = surname

        self.dateOfBirth = dateOfBirth

        self.hobbies = hobbies

 

#Creating Objects (Instances) of the person class

person1 = Person("Bob", "Jones", "06/10/1981", "E Sports")

person2 = Person("Jess", "Jones", "05/04/1980", "Astronomy")

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

Unlock more, it's free!

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

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

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.