OOP Fundamentals · Lesson 1 of 6

Why OOP is the interview question

Understand what problem OOP solves, why Pakistani employers test it by name, and write your first class.

Data This lesson: 123KB

Prerequisite, stated honestly: this course assumes you can already program a little — variables, functions, loops, from python-for-beginners or javascript-basics. OOP is a way of ORGANISING programs, and organising nothing teaches nothing.

Why this course exists: when we researched 100 Pakistani employers, five named object-oriented programming outright, and NETSOL — one of the country's largest software exporters — publishes candidate interview reports that test OOP alongside SQL and data structures. .NET, Java, and mobile interviews all lean on it. Notice what that means: employers interview on the CONCEPT, not a language. Learn it once, properly, and it transfers to Python, C#, Java, PHP and Dart — which is exactly how this course teaches it: Python syntax (the gentlest), portable ideas.

The problem OOP solves. Your fee-tracker programs kept data (arrays of student records) in one place and functions that work on them in another, connected only by discipline. At 200 lines that is fine. At 20,000 lines — a real ERP, a banking system — it collapses: any code anywhere can modify any data, and nobody can tell what is safe to change. OOP's move: bundle data and the functions that legitimately operate on it into one unit — a CLASS — and create working copies of it — OBJECTS. The class Student defines what every student HAS (name, fees) and can DO (pay, check status); each object is one actual student.

class Student:

def __init__(self, name, fee_total):
    self.name = name
    self.fee_total = fee_total
    self.fee_paid = 0
def pay(self, amount):
    self.fee_paid += amount

ayesha = Student("Ayesha", 60000)

ayesha.pay(20000)

print(ayesha.fee_paid) # 20000

__init__ runs at creation (the constructor — every OOP language has one under some name); self is the object being worked on (C# and Java call it this). Ten lines, and data plus behaviour now live together, created many times from one definition. The next three lessons are the four famous concepts interviewers actually probe — encapsulation, inheritance, polymorphism, abstraction — each shown as a solution to a real problem rather than a vocabulary word.

Try it yourself

Write the Student class exactly as shown, create three student objects with different fees, make payments, and print each student's name and balance from a loop over a list of the objects. You are combining objects with the arrays-and-loops you already know — that combination is real OOP code, day one.

Check what you learned

Create your free BvLogic ID to take the quiz and record your score.

Create your BvLogic ID
Continue to lesson 2 All lessons