Short Questions & Answers
● Classes & Objects ● Inheritance ● Polymorphism
● Encapsulation ● Abstraction ● Templates ● STL
Exam Prep • Interview Ready • Quick Revision
Topics Covered: Basics of OOP • Classes & Objects • Constructors & Destructors • Inheritance •
Polymorphism • Operator Overloading • Friend Functions • Virtual Functions • Abstract Classes • Templates •
Exception Handling • File I/O • STL • Smart Pointers
,OOP with C++ | Short Q&A Page 2
1. Fundamentals of OOP
Q1
What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm that organises software around objects — which bundle data (attributes) and
behaviour (methods) together. The four pillars are Encapsulation, Abstraction, Inheritance, and Polymorphism.
✎ Think of a real-world car: it has properties (colour, speed) and actions (accelerate, brake). OOP models this
directly.
Q2
What is a class and what is an object?
A class is a blueprint or template that defines the structure and behaviour of its objects. An object is a concrete
instance of that class, with its own memory and state.
class Car {
public:
string brand;
void drive() { /* ... */ }
};
Car myCar; // myCar is an object
Q3
What are the four pillars of OOP?
1. Encapsulation – bundling data and methods, hiding internals. 2. Abstraction – exposing only what is
necessary. 3. Inheritance – deriving new classes from existing ones. 4. Polymorphism – one interface, many
implementations.
✎ These four together make code modular, reusable, and easier to maintain.
Q4
What is the difference between a class and a structure in C++?
In C++ the only technical difference is default access: class members are private by default, struct members are
public by default. Conventionally, structs are used for plain data and classes for objects with behaviour.
struct Point { int x, y; }; // public by default
class Point { int x, y; }; // private by default
Q5
What is encapsulation?
Encapsulation means wrapping data and the functions that operate on it inside a class, and restricting direct
access to that data using access specifiers (private/protected). Access is then provided through public
getter/setter methods.
class BankAccount {
private:
double balance;
public:
void deposit(double amt) { balance += amt; }
double getBalance() { return balance; }
};
Prepared for Exam & Interview Preparation
, OOP with C++ | Short Q&A Page 3
Q6
What is abstraction? How is it achieved in C++?
Abstraction hides implementation details and shows only the essential features to the user. In C++ it is achieved
through abstract classes (classes with at least one pure virtual function) and interfaces.
class Shape {
public:
virtual double area() = 0; // pure virtual
};
✎ A TV remote is a great analogy — you press 'Volume Up' without knowing the internal circuitry.
Q7
What is the difference between abstraction and encapsulation?
Encapsulation is about HOW data is protected (access control, bundling). Abstraction is about WHAT is shown
to the user (hiding complexity). Encapsulation implements abstraction.
Prepared for Exam & Interview Preparation