Object Oriented
Programming
CLASSES, OBJECTS,
METHODS, INSTANCES
BY: RUIBIN LING
1. Introduction
to OOP 3. Objects and
Instances
2. What is a
Class? 4. Methods
Table of contents
5. Real-World
Example 7. Quiz
6. Why OOP
Matters 8. Thank you!
Table of contents
Introduction to OOP
Object-Oriented Programming(OOP) structures
software around objects instead of functions.
These objects represent real-world entities with data
(attributes) and behaviours (methods).
OOP has four core pillars: encapsulation, abstraction,
inheritance, and polymorphism. These pillars allow for
modular, reusablecode.
What is a Class?
A class is a blueprint defining the structure and
behaviour of objects. It declares attributes and
methods that all objects of this type will possess.
For example, a BankAccount class specifies that
every account must have balance and
account_number attributes, along with deposit()
and withdraw() methods.
Objects and Instances
An object is a concrete entity created from a class blueprint.
The process of creating an object is called instantiating, which
creates an instance. You can instantiate as many times as you want.
Both account1 and account2 are distinct instances of
BankAccount
Methods
A method is a function that belongs to an object.
They are defined within a class and operate on the
data associated with the instances of that class.
Methods enable objects to exhibit dynamic behaviour
while maintaining data integrity. They implement
rules, facilitate interactions, and provide controlled
access to private data. Methods also ensure code
reusability. The same method in a class can be
uniformly applied to all instances.
Methods belong to objects and can access and
manipulate the object’s data directly when they are
called. This is a form of encapsulation within objects
and is fundamental to OOP, allowing data and
functionality to be bundled together.
Real-World Example
One real-world example is this BankAccount class,
which roughly models the operations of real
financial institutions.
Each digital account has unique
identification(account_number) and tracks
individual balances(balance).
The deposit() and withdraw() methods replicate
real-world transactions, where deposits and
withdrawals can only be positive amounts, and you
cannot withdraw more money than you have.
Recepit messages are also generated.
Why OOP Matters Modularity
OOP forces code into
Reusability
Classes are templates
Maintainability
OOP models software
discrete classes, like a which promote just like real life.
Present with ease and wow any audience with
sealed container. reusability. Well- Updating systems
Canva Presentations. Choose from over a thousand becomes intuitive
When a bug emerges, designed classes can
professionally-made templates to fit any objective developers can fix it easily extend to many because code
or topic. Make it your own by customizing it with while it’s still in the different things as long structures reflect real-
text and photos. sealed container as they have some life concepts. Just like
without impacting form of similarity. how for example, an
others. Employee inherits
from Person.
1. What is a method?
Quick Quiz: 4. What happens when you call a method?
A) A function inside a class A) The class is redefined
B) A variable inside a class B) The object performs an action or updates its state
C) A comment in code C) A new object is created
D) An error message D) The method becomes static
2. What is instantiation? 5. Which code snippet correctly creates a Car instance?
A) Copying a variable A) car = Car("Tesla")
B) Deleting an object B) car = new Car("Tesla")
C) Creating an object from a class C) car = Car.create("Tesla")
D) Breaking code into modules D) car = Car.self("Tesla")
3. How is a class different from an object? 6. How many times can a class be instantiated?
A) A class is a specific instance A) Once
B) A class is a blueprint; an object is its concrete manifestation B) Twice
C) A class holds data; an object defines behaviour C) Up to 10 times
D) They are identical terms D) Unlimited times
Answer Key: A, C, B, B, A, D
Thank you!
Avery Davis