Chapter 1
C++ Classes, Objects & OOP Principles
Master the four pillars of OOP (Encapsulation, Abstraction, Inheritance, Polymorphism), constructors, and access specifiers.
C++: Object Oriented Programming
Created by Bjarne Stroustrup in 1979 as an extension of C with classes.
Four Pillars of OOP:
- Encapsulation: Bundling data members and member functions into a single unit (Class) and restricting direct access using private/protected specifiers.
- Abstraction: Hiding complex background implementation details and exposing only essential interface features.
- Inheritance: Deriving new classes (Derived / Child) from existing classes (Base / Parent) to promote code reusability.
- Polymorphism: Ability of a function or operator to take multiple forms (Compile-time via function overloading / operator overloading, and Run-time via Virtual Functions).
Hands-on Laboratory Procedures & Shortcuts
Follow the steps below to practice directly on your computer.
Complete C++ Class Example:
#include <iostream>
using namespace std;
class Student {
private:
int roll;
string name;
public:
// Constructor
Student(int r, string n) : roll(r), name(n) {}
void display() {
cout << "Roll: " << roll << " | Name: " << name << endl;
}
};
int main() {
Student s1(101, "Rinki Mallick");
s1.display();
return 0;
}
Watch the video class above while following along with the practical exercises.
Key Summary & Revision Bullet Points
Quick cheat-sheet to review before online examinations.
• Constructor: Special member function having the same name as the class, invoked automatically upon object creation, has no return type.
• Destructor: Preceded by a tilde (
• Destructor: Preceded by a tilde (
~), releases resources when an object goes out of scope. Frequently Asked Viva & Exam Questions
Review these standard questions frequently asked in diploma exams and job interviews.
Q1: What is a Virtual Function in C++?
Ans: A member function declared with the
Ans: A member function declared with the
virtual keyword in a base class and redefined in a derived class to achieve Run-Time Polymorphism via base class pointers. Interactive Chapter Quiz
Test your mastery immediately! Click an option to see instant answer feedback.
Q1 Who created the C++ programming language?
A. Dennis Ritchie
B. Bjarne Stroustrup
C. James Gosling
D. Ken Thompson
Explanation: Bjarne Stroustrup developed C++ at Bell Laboratories in 1979.
Q2 What is the default access specifier for members of a class in C++?
A. public
B. protected
C. private
D. internal
Explanation: Class members are private by default in C++ (in structs, they are public).
Q3 Which special member function has the same name as the class and initializes objects?
A. Destructor
B. Constructor
C. Virtual Function
D. Friend Function
Explanation: Constructors initialize objects automatically at instantiation.
Q4 Which symbol precedes the name of a Destructor in C++?
A. #
B. *
C. ~
D. &
Explanation: A tilde (~) precedes a destructor declaration.
Q5 Which concept enables Run-Time Polymorphism in C++?
A. Function Inlining
B. Virtual Functions
C. Friend Classes
D. Templates
Explanation: Virtual functions resolved via vtable pointers enable runtime dynamic polymorphism.