Photo AI
Last Updated Sep 27, 2025
Revision notes with simplified explanations to understand Objects (OOP) quickly and effectively.
310+ students studying
In Object-Oriented Programming (OOP), a class is a blueprint that defines the structure and behaviour of objects. An object is an instance of a class, representing a specific entity with attributes (data) and methods (functions) that define its state and behaviour. Understanding how to create and use objects is fundamental to OOP and is essential for writing organised, reusable, and modular code.
Example:
class Car:
def __init__(self, make, model):
self.make = make
self.model = model
# Creating objects of the Car class
car1 = Car("Toyota", "Corolla")
car2 = Car("Honda", "Civic")
Here, car1 and car2 are objects (or instances) of the Car class. Each object has its own unique values for make and model.
Example:
print(car1.make) # Output: Toyota
print(car2.make) # Output: Honda
Even though car1 and car2 are instances of the same class (Car), they have different values for the make attribute.
Methods are functions defined within a class that describe the behaviours of objects. They can use and modify the object's attributes.
Example:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
print(f"Hi, I'm {self.name} and I'm {self.age} years old.")
# Creating a Person object and calling its method
person1 = Person("Alice", 30)
person1.introduce() # Output: Hi, I'm Alice and I'm 30 years old.
You can change the values of an object's attributes directly or by using methods, allowing objects to update their state during the program's execution.
Example:
person1.age = 31 # Directly modifying an attribute
print(person1.age) # Output: 31
Each object operates independently, so you can create multiple instances of a class, each with its own attribute values and behaviours.
Example:
person2 = Person("Bob", 25)
person1.introduce() # Output: Hi, I'm Alice and I'm 31 years old.
person2.introduce() # Output: Hi, I'm Bob and I'm 25 years old.
Below is an example program that defines a Book class and creates multiple Book objects.
class Book:
def __init__(self, title, author, year):
self.title = title
self.author = author
self.year = year
def get_description(self):
return f"{self.title} by {self.author}, published in {self.year}"
# Creating Book objects
book1 = Book("1984", "George Orwell", 1949)
book2 = Book("To Kill a Mockingbird", "Harper Lee", 1960)
# Accessing attributes and calling methods on objects
print(book1.get_description()) # Output: 1984 by George Orwell, published in 1949
print(book2.get_description()) # Output: To Kill a Mockingbird by Harper Lee, published in 1960
In this example:
To trace an object, you can inspect its attribute values at any point in the program.
Example:
print(book1.title) # Outputs: 1984
You can update an object's state by changing its attributes directly or through methods.
Example:
book1.year = 1950 # Updates the publication year
print(book1.get_description()) # Output: 1984 by George Orwell, published in 1950
Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!
70 flashcards
Flashcards on Objects (OOP)
Revise key concepts with interactive flashcards.
Try Computer Science Flashcards7 quizzes
Quizzes on Objects (OOP)
Test your knowledge with fun and engaging quizzes.
Try Computer Science Quizzes29 questions
Exam questions on Objects (OOP)
Boost your confidence with real exam questions.
Try Computer Science Questions27 exams created
Exam Builder on Objects (OOP)
Create custom exams across topics for better practice!
Try Computer Science exam builder12 papers
Past Papers on Objects (OOP)
Practice past papers to reinforce exam experience.
Try Computer Science Past PapersDiscover More Revision Notes Related to Objects (OOP) to Deepen Your Understanding and Improve Your Mastery
Join 500,000+ A-Level students using SimpleStudy...
Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!
Report Improved Results
Recommend to friends
Students Supported
Questions answered