0% found this document useful (0 votes)
6 views4 pages

OOP CPP Full Notes Basic To Advanced

The document provides comprehensive notes on Object-Oriented Programming (OOP) in C++, covering fundamental concepts such as encapsulation, inheritance, and polymorphism. It includes details on classes, constructors, destructors, memory management, and advanced topics like smart pointers and exception handling. Additionally, it features interview questions related to OOP principles and practices.

Uploaded by

Saurav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

OOP CPP Full Notes Basic To Advanced

The document provides comprehensive notes on Object-Oriented Programming (OOP) in C++, covering fundamental concepts such as encapsulation, inheritance, and polymorphism. It includes details on classes, constructors, destructors, memory management, and advanced topics like smart pointers and exception handling. Additionally, it features interview questions related to OOP principles and practices.

Uploaded by

Saurav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOP in C++ — Complete Notes (Basic to

Advanced)

1. Introduction to OOP
Object-Oriented Programming (OOP) is a paradigm based on objects and classes.

1 Improves code reusability


2 Enhances modularity
3 Improves maintainability

2. Core Principles
1 Encapsulation – Data hiding
2 Abstraction – Hiding complexity
3 Inheritance – Code reuse
4 Polymorphism – Multiple behavior

3. Class and Object


class Car {
public:
int speed;
void drive() {}
};
Car c1;

4. Encapsulation
class A {
private:
int x;
public:
void setX(int v){ x = v; }
int getX(){ return x; }
};

5. Constructors
1 Default
2 Parameterized
3 Copy
4 Move
class A {
public:
A(){}
A(int x){}
A(const A &obj){}
};

6. Destructor
~A(){
// cleanup
}

7. Inheritance
1 Single
2 Multiple
3 Multilevel
class A{};
class B: public A{};

8. Polymorphism

Compile Time
1 Function overloading
2 Operator overloading

Runtime
1 Virtual function
2 Overriding

9. Virtual Functions
class Base {
public:
virtual void show(){}
};

10. Abstract Class


virtual void display() = 0;

11. Operator Overloading


Complex operator+(Complex &c);

12. Friend Function


Can access private members

13. Static Members


Shared across objects
14. this Pointer
Points to current object

15. Memory Management


int *p = new int;
delete p;

16. Smart Pointers


1 unique_ptr
2 shared_ptr
3 weak_ptr

17. Advanced Concepts

Deep vs Shallow Copy


Shallow copy copies pointer, deep copy copies data.

Rule of 3/5
Destructor, Copy ctor, Copy assignment (+ move).

Virtual Destructor
Ensures proper cleanup using base pointer.

Object Slicing
Derived part lost when assigned to base.

RAII
Resource Acquisition Is Initialization.

18. Exception Handling


try { throw 1; }
catch(int e){}

19. OOP with STL


Use classes with vector, map, etc.

20. Interview Questions & Answers


1 What is OOP?
2 Difference between abstraction and encapsulation
3 Why virtual destructor?
4 What is vtable?
5 Explain polymorphism with example

You might also like