What is Object-Oriented Programming (OOP)?
Object-Oriented Programming is a programming paradigm in which the entire software is designed as a collection of objects that interact with each other. Each object consists of data and the methods that manipulate this data.
The four main pillars of OOP are:
Why should we use Object-Oriented Programming?
The primary advantage of OOP lies in improved code manageability, which includes:
What are the key features of OOP?
The fundamental features of OOP, often referred to as the four pillars, are:
Encapsulation:
Data Abstraction:
Polymorphism:
Inheritance:
Besides OOP, what other programming paradigms exist?
A programming paradigm is the approach or methodology used to write programs. The main paradigms include:
Imperative Programming:
Declarative Programming:
How does Structured Programming differ from Object-Oriented Programming?
Structured Programming is a technique viewed as a precursor to OOP, usually consisting of well-organized, separated modules.
Key Differences:
Which programming languages are commonly used for OOP?
Popular programming languages that support OOP include:
What are the advantages and disadvantages of using OOP?
Advantages of OOP:
Disadvantages of OOP:
How is a class defined in OOP?
A class is a user-defined data type that contains data members (attributes) and member functions (methods) that operate on those data members.
It acts as a blueprint or template for creating objects with common properties and behaviors.
Key Points:
Example:
What is an object in OOP?
An object is an instance of a class. Class data members and methods cannot be used directly — an object must be created to access them.
Key Characteristics:
Key Points:
Example:
How much memory does a class consume?
Classes themselves do not consume memory — they serve merely as templates or blueprints.
Memory allocation occurs only when objects are instantiated, at which point the class members and methods are initialized in memory.
Key Points:
Example:
What does encapsulation mean in OOP?
Encapsulation is the process of binding data and the methods that manipulate them into a single unit in such a way that sensitive data is hidden from users.
It is implemented in two ways:
Data Hiding:
Data Binding:
Benefits:
Example:
What is abstraction in the context of OOP?
Abstraction is closely related to encapsulation and is crucial in OOP. It refers to displaying only the necessary information to the user while hiding irrelevant details and complexity.
Key Concept:
How it is implemented:
Benefits:
Example:
What are access specifiers, and why are they important in OOP?
Access specifiers are special keywords used to define or control the accessibility of entities like classes, methods, and variables.
Types of Access Specifiers:
Public:
Private:
Protected:
Why They Are Important:

What is an abstract class?
An abstract class is designed to serve as a base class for inheritance and cannot be instantiated directly. It may include both abstract methods (without implementation) and non-abstract methods (with implementation).
Key Characteristics:
Language-Specific Implementation:
Example:
What is an interface in programming?
An interface is a unique type of class that contains only method declarations without any implementation. Objects cannot be created directly from an interface.
Key Characteristics:
Supports Multiple Inheritance:
Example:
Note (Java 8+): Interfaces can now have `default` and `static` methods with implementations.
How does an abstract class differ from an interface?
Both abstract classes and interfaces are used to achieve abstraction, but they differ significantly in design and capability.
Abstract Class:
Interface:
Rule of Thumb: Use an abstract class for "is-a" relationships with shared code, and an interface for "can-do" or behavioral contracts.
What is inheritance, and what is its purpose?
Inheritance is a fundamental OOP concept where a child class (derived/subclass) inherits properties and behaviors from a parent class (base/superclass).
Main Purposes:
Key Terminology:
What is inherited:
Example:

What types of inheritance are there?
The different types of inheritance are:
Single Inheritance:
Multiple Inheritance:
Multilevel Inheritance:
Hierarchical Inheritance:
Hybrid Inheritance:
Note: The availability of these types depends on the programming language used.
Are there any limitations to inheritance?
While inheritance is a powerful OOP feature, it comes with notable limitations:
Performance Overhead:
Tight Coupling:
Unexpected Errors:
Diamond Problem:
Reduced Encapsulation:
Fragile Base Class Problem:
What are virtual functions and pure virtual functions?
Virtual Function:
Pure Virtual Function:
Key Difference:
What are friend functions and friend classes?
Friend Function:
Friend Class:
Important Rules:
Example:
What is the difference between a structure and a class in C++?
A structure in C++ is a user-defined data type similar to a class, with the following notable differences:
Default Access:
Declaration Keyword:
Memory:
Abstraction:
Inheritance:
General Use:
What is polymorphism, and what are its types?
Polymorphism means having many forms — it is the ability of code to behave differently based on context. For example, in C++, multiple functions can share the same name but operate differently depending on context.
Two Types of Polymorphism:
Compile-Time Polymorphism (Static / Early Binding):
- Method Overloading: Same function name, different parameters.
- Operator Overloading: Same operator behaves differently with different types.
Runtime Polymorphism (Dynamic / Late Binding):
- Method Overriding: Derived class provides its own implementation of a base class method.
- Requires virtual functions in C++.
Example:

How do overloading and overriding differ?
Overloading (Compile-Time Polymorphism):
Overriding (Runtime Polymorphism):
Key Difference: Overloading is about multiple implementations of the same name in one class; overriding is about replacing a parent's implementation in a child class.
What is static polymorphism?
Static polymorphism, also known as compile-time polymorphism, links an object to a particular function or operator during compile time.
How it is Achieved:
Method Overloading:
Operator Overloading:
Key Characteristics:
Example:
What is dynamic polymorphism?
Dynamic polymorphism, or runtime polymorphism, determines the actual function implementation during program execution rather than at compile time.
How it is Achieved:
How it Works:
Key Characteristics:
Example:
How does C++ implement polymorphism?
C++ supports both types of polymorphism:
Compile-Time Polymorphism:
Runtime Polymorphism:
vtable Mechanism:
Example:
```cpp
class Animal {
public:
virtual void sound() { cout << "Some sound"; }
};
class Dog : public Animal {
public:
void sound() override { cout << "Bark"; }
};
```

What is a constructor?
A constructor is a special code block that initializes a newly created object. It is automatically called when an object is instantiated.
Key Characteristics:
Language Variations:
Purpose:
Example:

What are the different types of constructors in C++?
Common constructor types in C++ include:
Default Constructor:
Non-Parameterized Constructor:
Parameterized Constructor:
Copy Constructor:
Move Constructor (C++11):

What is a destructor?
A destructor is a special method called automatically when an object is destroyed or goes out of scope. It frees the resources and memory occupied by an object.
Key Characteristics:
Language Variations:
Purpose:
Example:
Can constructors in a class be overloaded?
Yes, constructors can be overloaded in a class.
How it Works:
Example in Java:
```java
class Car {
Car() { /* default */ }
Car(String color) { /* with color */ }
Car(String color, int speed) { /* with color and speed */ }
}
```
Benefits:
Note: Python achieves similar behavior using default parameter values in `__init__` since it doesn't support traditional method overloading.
Can destructors in a class be overloaded?
No, destructors cannot be overloaded. A class can only have one destructor.
Reasons Why:
Key Facts:
Contrast with Constructors:
What is an exception?
An exception is a special runtime event that disrupts normal program execution, often caused by illegal operations or unexpected input that the program isn't designed to handle.
Common Causes:
Types of Exceptions:
Checked Exceptions (Java):
Unchecked Exceptions (Java):
Key Point:
What does exception handling mean?
Exception handling is a mechanism to anticipate and manage undesirable program states to prevent crashes and allow programs to continue running gracefully.
Core Constructs:
try block:
catch block:
finally block:
throw / throws:
Benefits:
Example:

What is garbage collection in OOP?
Garbage collection in OOP refers to automatic memory management that frees up memory by removing objects no longer in use. This prevents memory leaks and related errors caused by improper handling of multiple objects in memory.
How it Works:
Languages with Automatic GC:
Languages without Automatic GC:
Benefits:

Can a Java application run without using OOP concepts?
No, Java applications rely fundamentally on OOP concepts and cannot run without them.
Why:
Contrast with C++:
Note:
Is it always necessary to create objects from a class?
No, it is not always necessary to create objects from a class.
When Objects ARE Required:
When Objects ARE NOT Required:
Examples:
```java
// No object needed — static method
Math.sqrt(16);
// Object needed — instance method
Car myCar = new Car();
myCar.accelerate();
```
Design Pattern:
What will be the output of the following code involving multiple inheritance in C++?
Output:
```
BaseClass1 constructor called
BaseClass2 constructor called
DerivedClass constructor called
```
Explanation:
In multiple inheritance, when the derived class constructor is invoked, it automatically calls the base classes' constructors in left-to-right order as specified in the derived class declaration.
For example, if the derived class is declared as:
```cpp
class DerivedClass : public BaseClass1, public BaseClass2
```
Then:
Destruction happens in the reverse order:

What will be the output of the following Java code with static blocks?
Output:
```
b
c
a
100
```
Explanation:
Key Points about Static Blocks:
What will the output be for the overloaded main method in Java shown below?
Output:
```
Main1
```
Explanation:
Key Rule:
Can you predict the output of the type conversion constructor example in C++?
Output:
```
i = 10
i = 20
```
Explanation:
Key Concepts:
Can you predict the output related to the diamond problem and sizeof operator in C++?
Output:
```
80
```
Explanation:
The Diamond Problem:
Solution — Virtual Inheritance:
```cpp
class DerivedBaseClass1 : virtual public BaseClass { };
class DerivedBaseClass2 : virtual public BaseClass { };
```

What is the output of the below C++ program demonstrating multilevel inheritance?
Output:
```
Inside B
```
Explanation:
Key Rule:
What is a class?
A class can be understood as a blueprint or template that contains member data (values) and behaviors (functions).
Key Points:
Components of a Class:
Example:
What is an object?
An object is an instance of a class that contains the actual instances of the members and behaviors defined by the class template.
Real-World Analogy:
Key Characteristics:
Example:
What is encapsulation?
Encapsulation can be visualized as the process of placing all necessary data and methods inside a capsule and presenting this capsule to the user, hiding unnecessary details.
Two Key Aspects:
Data Hiding:
Data Binding:
Benefits:
Example:
What is inheritance?
Inheritance means receiving certain qualities or behaviors from a parent to an offspring. In OOP, it is the mechanism by which a child class or object is created using the definition of a parent class.
Purpose:
Key Terminology:
What Gets Inherited:
Types: Single, Multiple, Multilevel, Hierarchical, and Hybrid inheritance.
Example:
Can you explain inheritance with an example?
Inheritance is a key feature of OOP where an entity inherits characteristics and behaviors from another entity and adopts them as its own.
Real-World Example — Vehicles:
Consider vehicles like cars, trucks, and buses. They have distinct features but share common components such as:
Without Inheritance:
With Inheritance:
```java
class Vehicle {
void applyBrakes() { System.out.println("Brakes applied"); }
void steer() { System.out.println("Steering"); }
}
class Car extends Vehicle {
void openSunroof() { System.out.println("Sunroof opened"); }
}
```
Benefits shown:
What is a copy constructor?
A copy constructor is a special type of constructor that initializes a new object by copying an existing object of the same class. Essentially, it clones the object and its values into another object.
Key Characteristics:
Types of Copy:
Shallow Copy:
Deep Copy:
Language Notes:
What is a destructor?
Unlike constructors which initialize objects and allocate memory, destructors are special methods that free the resources and memory occupied by an object. They are automatically called when an object is destroyed or goes out of scope.