Object Oriented Programming

A complete, exam-ready guide to Object Oriented Programming — covering the core concepts, all five types of inheritance with diagrams, and a full OOP vs POP comparison. Bookmark this page for revision.

1. Procedure Oriented Programming (POP)

Procedure Oriented Programming is the conventional, older style of programming where a program is broken into small parts — functions — which are then combined together to form the complete program. In this approach, functions take center stage while data is treated as secondary.

  • Variables are either local (created inside sub-programs, accessible only within that module) or global (created in the main module, accessible from anywhere in the program).
  • Because global variables can be reached and changed from any part of the program, the risk of accidental data alteration is high.
Exam tip: If asked "what is the biggest weakness of POP?" — the answer is lack of data security, since data exists as exposed global variables.

2. Introduction to OOP

Object Oriented Programming (OOP) is the modern approach to programming, built around the idea of objects rather than functions.

  • Real-world entities are treated as objects.
  • Objects with similar properties are grouped into a class.
  • Classes can be organized under a super class — and thanks to inheritance, any change made to the super class automatically passes down to its sub classes.
  • Unlike POP, OOP gives priority to data over functions, and data can be hidden, greatly reducing the risk of unwanted alteration.
One-line definition to memorize: OOP is a programming paradigm based on objects, which bundle data and the functions that operate on it, while emphasizing data security through hiding.

3. Benefits of OOP over POP

#Benefit
1Emphasis is on data, not procedure
2Data hiding gives security — POP's biggest weakness is solved
3Inheritance allows easy reuse of existing code
4Polymorphism exists in OOP but not in POP
Exam tip: This table is a classic 2–4 mark short question — "List any two/four advantages of OOP over POP."

4. Features of OOP

These seven features are the heart of the OOP unit — almost every exam has at least one question built directly from this section. Each one below is explained in three layers: what it is, why/how it works, and a worked example, so you can write full-mark answers whether the question is worth 2 marks or 8.

4.1 Class

A class is a user-defined data type — a blueprint or template that defines what data (attributes) and what behavior (functions) every object created from it will have. Think of a class the way you'd think of the architectural plan for a house: the plan itself isn't a house you can live in, but it precisely determines what every house built from it will look like.

A class by itself does not occupy memory for its data — memory is only allocated once an object is created from it. A single class can be used to create any number of objects, and each object gets its own independent copy of the data defined by the class.

Example: class Vehicle defines attributes like speed, colour, fuelType and functions like start(), stop(). Car, Bus, and Truck are all separate objects that can be created from this one class, each with different values for those attributes.
Exam tip: If a question asks "why is a class called a user-defined data type?" — answer that, just like int or float are built-in data types, a class lets the programmer define a brand-new type suited to their own problem.

4.2 Object

An object is a real, existing instance of a class — it's what you actually work with when the program runs. If the class is the blueprint, the object is the actual house built from it, sitting in memory with real values.

Every object has two parts:

  • Attributes (state) — the data/characteristics that describe the object, such as colour, size, or weight.
  • Behavior (methods) — the functions/actions the object can perform, such as move() or turn().

Multiple objects created from the same class are independent of each other — changing one object's data does not affect another object's data, even though both come from the same class.

Example: From class Car, you might create two objects: myCar (blue, 1200kg) and friendsCar (black, 1400kg). Both are Car objects, but their attribute values are completely independent.

4.3 Inheritance

Inheritance is the mechanism that lets a new class (called the derived class or sub class) be built from an already existing class (called the base class or super class), automatically picking up its features.

Why this matters: without inheritance, every new class would have to be written completely from scratch, even if it shares 90% of its behavior with something that already exists. Inheritance lets a programmer write the shared logic once in the base class, and every derived class reuses it — and if the base class is later updated, all its derived classes automatically get that update too.

A derived class can also add its own new attributes and functions on top of what it inherits, or override (redefine) an inherited function to behave differently.

Example: A base class Animal defines name, sound, and eat(). A derived class Dog automatically inherits all of these, and can additionally define its own attribute breed and its own function fetch().
Exam tip: Remember the direction — the derived class inherits FROM the base class, not the other way around. Getting this reversed is a very common mistake in diagram-based answers.

4.4 Polymorphism

Polymorphism comes from Greek — "poly" (many) + "morph" (forms) — and refers to the ability of the same function name or operator to take on different behavior depending on the context it's used in.

This is achieved mainly in two ways:

  • Operator overloading — the same operator performs different operations depending on the data type of its operands.
  • Function/method overloading — multiple functions share the same name but differ in the number or type of parameters they accept, and the correct one is automatically selected based on how it's called.

The practical benefit is that a programmer doesn't need to invent a new name for every slightly different version of an operation — one intuitive name can cover many related uses, which makes code easier to read and remember.

Example: The + operator performs numeric addition when used with integers (5 + 3 = 8), but performs string concatenation when used with text ("Hi " + "there" = "Hi there") — same operator, two different behaviors depending on context.

4.5 Data Hiding

Data hiding is the feature that keeps an object's internal data inaccessible from outside the class — it can only be reached and modified through the class's own functions, never directly from outside code.

This matters because it stops other, unrelated parts of a program from accidentally (or carelessly) corrupting an object's data. Instead, all changes must go through controlled "gateway" functions that the class itself provides, which can include validation or rules before allowing a change.

Example: In a class BankAccount, the balance variable is hidden — no outside code can directly set balance = -500. It can only be changed through functions like deposit() or withdraw(), which can enforce rules such as "balance cannot go negative."

4.6 Encapsulation

Encapsulation is the process of binding data and the functions that operate on that data together into a single unit — the class. It's often described using the analogy of a medicine capsule: different ingredients are sealed together inside one shell, working as a single unit rather than loose, separate pieces.

OOP places more emphasis on data than on procedure, so encapsulation exists to make sure that data is always accessed and modified only by the functions specifically meant to handle it — a function belonging to an unrelated class cannot casually use or alter data it has no business touching. This keeps related code organized together and reduces the chance of unintended interference between different parts of a program.

Exam tip: Data hiding and encapsulation are often confused. Encapsulation = bundling data + functions together into one class. Data hiding = restricting outside access to that data. Encapsulation is what makes data hiding possible.

4.7 Overloading

Overloading is the feature that allows more than one function to share the same name (distinguished by different parameters), or allows the same operator to be reused for multiple, different tasks.

It is worth noting that overloading is not a separate, standalone feature from polymorphism — it is one of the concrete techniques through which polymorphism is achieved in a program. When a class has several functions with the same name but different parameter lists, the correct version to run is automatically selected based on how the function is called.

Example: A class might define three versions of area() — one accepting a single side (for a square), one accepting length and width (for a rectangle), and one accepting a radius (for a circle) — all sharing the same function name.
Exam tip: A common mix-up is Overloading vs Polymorphism. Remember: overloading is one example/type of polymorphism, not a separate concept — polymorphism is the broader idea, overloading is one way to implement it.


5. Types of Inheritance

Draw and label each of these diagrams by hand in your exam — examiners award marks for correctly labeled boxes and arrows.

1️⃣ Single Inheritance

Exactly one derived class inherits from exactly one base class. It is the simplest form of inheritance, forming a straight, one-step relationship.

One base class → one derived class. The simplest, most direct form of inheritance.

Example: class Employee derived from class Person.
Base Class
Derived Class

2️⃣ Multiple Inheritance

A single derived class inherits from two or more base classes at the same time, combining features from each parent into one child class.

One derived class inherits from two or more base classes at the same time.

Example: class FlyingCar derived from both class Car and class Aircraft.
Class A
Class B
Class C

3️⃣ Multilevel Inheritance

A class is derived from a class, which is itself already derived from another class — forming a chain of inheritance across multiple levels, like a family lineage.

A chain — a class is derived from a class, which is itself derived from another class.

Example: class Grandparent → class Parent → class Child.
Class A
Class B
Class C

4️⃣ Hierarchical Inheritance

Multiple derived classes inherit from a single base class — the opposite structure of multiple inheritance. Each child class independently reuses the parent's features.

Multiple classes derived from one single base class — the opposite structure of multiple inheritance.

Example: class Shape is the base for both class Rectangle and class Circle.
Shape
Rectangle
Circle

5️⃣ Hybrid Inheritance

A combination of two or more types of inheritance above. The derived class can be reached through multiple paths from a common base class — also known as virtual inheritance.

A combination of two or more inheritance types above; also called virtual inheritance. The derived class has multiple paths to reach a base class.

Example: class D inherits from both class B and class C, which both inherit from a common class A (a mix of hierarchical + multiple inheritance).
Class A
Class B
Class C
Class D
Exam tip: Don't confuse Multiple and Multilevel — Multiple = many parents, one child (side by side). Multilevel = a chain, like grandparent → parent → child.

6. Advantages and Disadvantages of OOP

✅ Advantages

  1. Code repetition is reduced through inheritance.
  2. Data is more secure due to data hiding.
  3. Existing classes can act as reusable library classes.
  4. It models the real world accurately.
  5. Code reusability is much easier than in POP.

❌ Disadvantages

  1. High compiler and runtime overhead.
  2. Developers must think and design in an "object-oriented" way.
  3. Requires strong mastery of software engineering concepts.
  4. Beneficial mainly for large and complex projects.

7. OOP vs POP — Comparison Table

#OOPPOP
1Emphasizes data over procedureEmphasizes procedure over data
2Program divided into objectsProgram divided into functions
3Inheritance enables reusabilityInheritance is not possible
4Models real-world problemsDoes not model real-world problems
5Data security is a main priorityNo data security
6Follows a bottom-up approach — e.g. C++Follows a top-down approach — e.g. C
Exam tip: This table alone can answer a full 5-mark "Differentiate between OOP and POP" question — memorize all six points with the C++ vs C examples.

8. Applications of OOP

  • Software development
  • Image processing and pattern recognition
  • Web application development
  • Artificial Intelligence
  • Database design

🧠 Quick Revision Summary

  • POP → procedure-focused, weak data security, global/local variables.
  • OOP → object-focused, strong data security, models the real world.
  • 7 Core Features: Class, Object, Inheritance, Polymorphism, Data Hiding, Encapsulation, Overloading.
  • 5 Types of Inheritance: Single, Multiple, Multilevel, Hierarchical, Hybrid.
  • OOP vs POP: memorize the 6-point comparison table.
  • Languages: C++ (OOP, bottom-up) vs C (POP, top-down).

✍️ Practice Questions

  1. Define OOP. How is it different from POP? (5 marks)
  2. Explain any four features of OOP with examples. (8 marks)
  3. Draw and explain the five types of inheritance. (10 marks)
  4. What are the advantages and disadvantages of OOP? (5 marks)
  5. Differentiate between Overloading and Polymorphism.
  6. List any three real-world applications of OOP.
Netra Koirala

Netra Koirala

Computer Science Educator

Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.

Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.

Featured Post

Object Oriented Programming

A complete, exam-ready guide to Object Oriented Programming — covering the core concepts, all five types of inheritance with diagrams,...

Followers