Objects (OOP) (Cambridge (CIE) A Level Computer Science): Revision Note
Exam code: 9618
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
Programming objects (OOP)
How do you program an object?
Pseudocode

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!
Did this page help you?