Studyfin Studyfin ✨ Sign up free

Object-oriented programming basics

Grade 9 · Coding · Free lesson

Welcome! Today we will explore Object-Oriented Programming, a smart way to organize code using real-world ideas.

In coding, we often need to represent real-world things. Object-Oriented Programming, or OOP, lets us group data and actions together into neat packages called objects.

blog

Think of a Class as a blueprint, like a drawing for a house. An Object is the actual house built from that blueprint. You can build many unique houses from just one blueprint.

Class (Blueprint) Object (Instance)

Objects have two main parts: attributes and methods. Attributes are details that describe the object, like its color. Methods are actions the object can perform, like making a sound.

Object: Dog • breed: "Beagle" (Attribute) • age: 3 (Attribute) • bark() (Method) • run() (Method)
✏️ Worked example

Let's design a simple 'Car' class. We want to create two different car objects from this class, each with its own color.

  1. First, we define the blueprint. We create a class named 'Car'.
  2. Next, we give our class an attribute called 'color' to store each car's look.
  3. Then, we write a method called 'drive()' so our car objects can perform an action.
  4. Now, we build our first object: a red car. We set its color attribute to 'red'.
  5. Finally, we build our second object: a blue car. We set its color attribute to 'blue'. Both cars can use the drive() method!
binder
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons