Introduction to OOP in C++

Unit 1 Β· Topic 1.1⏱ 10 min readπŸ“Š 1 diagram❓ 5 MCQs

Introduction

Object-Oriented Programming (OOP) organizes software as a collection of objects that combine data and behavior. C++ supports both procedural (POP) and object-oriented paradigms.

OOP focuses on objects rather than procedures, improving modularity, reusability, and maintainability.

The Four Pillars

Four pillars of OOP: encapsulation, abstraction, inheritance, polymorphism

Fig 1.1 β€” The four pillars of Object-Oriented Programming.

POP vs OOP

Procedural (POP)

  • Emphasis on functions/procedures
  • Top-down approach
  • Global data sharing
  • Less data hiding

Object-Oriented (OOP)

  • Emphasis on objects
  • Bottom-up approach
  • Data hiding/encapsulation
  • Reusability via inheritance

Definition

OOP: A paradigm that models software as interacting objects, each bundling data and the methods operating on it.

C++ Code Example

#include <iostream>
using namespace std;
class Student {
    string name;
    int age;
public:
    void set(string n, int a){ name=n; age=a; }
    void show(){ cout<<name<<" "<<age<<endl; }
};
int main(){
    Student s; s.set("Ravi",20); s.show();
    return 0;
}

Important Questions

Short Questions

  1. Define OOP.
  2. List the four pillars of OOP.
  3. Difference between POP and OOP?
  4. What is an object?

Long Questions

  1. Explain OOP features with examples.
  2. Compare procedural and object-oriented programming.

MCQ Practice

1. OOP stands for:

  • Object-Oriented Programming
  • Object-Only Programming
  • Ordered Object Programming
  • Open Object Programming
Answer: Object-Oriented Programming.

2. Which is NOT a pillar of OOP?

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Compilation
Answer: Compilation.

3. POP follows which approach?

  • Top-down
  • Bottom-up
  • Object-first
  • None
Answer: top-down.

4. C++ was developed by:

  • Bjarne Stroustrup
  • Dennis Ritchie
  • James Gosling
  • Guido van Rossum
Answer: Bjarne Stroustrup.

5. An object is:

  • An instance of a class
  • A function
  • A variable type
  • A keyword
Answer: an instance of a class.

Quick Revision

  • OOP = objects bundling data + behavior.
  • Pillars: encapsulation, abstraction, inheritance, polymorphism.
  • POP: top-down, functions; OOP: bottom-up, objects.
  • C++ supports both paradigms.