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

OOPs CPP Detailed Notes

The document provides a detailed overview of Object-Oriented Programming (OOP) in C++, covering key concepts such as classes, objects, inheritance, polymorphism, templates, exception handling, and I/O formatting. It explains essential features like data hiding, encapsulation, and abstraction, along with practical examples. Additionally, it discusses advanced topics like virtual functions, manipulators, and streams in C++.

Uploaded by

ddhhoonnii7781
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

OOPs CPP Detailed Notes

The document provides a detailed overview of Object-Oriented Programming (OOP) in C++, covering key concepts such as classes, objects, inheritance, polymorphism, templates, exception handling, and I/O formatting. It explains essential features like data hiding, encapsulation, and abstraction, along with practical examples. Additionally, it discusses advanced topics like virtual functions, manipulators, and streams in C++.

Uploaded by

ddhhoonnii7781
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
You are on page 1/ 4

OOPs in C++ - Detailed Notes (Easy Language)

Unit-wise Detailed Explanation

1. Introduction to OOP
- OOP (Object Oriented Programming): A style where we model real-world objects.
- Key idea: Data + Functions = Object.
- Benefits: Code reuse, better security (data hiding), easy maintenance, easy to expand.

2. Features of OOP
- Data Hiding: Private data can't be accessed directly from outside class.
Example:
class Demo { private: int x; };

- Classes & Objects: Class = Blueprint; Object = Instance.


Example:
class Car { public: void start(); };
Car obj;

- Encapsulation: Wrapping data & functions together.


- Abstraction: Show only necessary info. (Example: Driving car, no need to know engine working).
- Inheritance: Reuse existing class.
Example:
class A { }; class B: public A { };

- Polymorphism: One thing, many forms.


Example: Function overloading (same function name, diff parameters).

3. Class and Object


- Access Specifier: Controls access to members.
private: accessible within class only
protected: accessible within class and derived class
public: accessible from anywhere

- Default visibility in class = private.


- Friend Function: Function that can access private data.
Example:
friend void show(Demo);
- Constructor: Special function, same name as class.
Auto-call on object creation.
Types:
- Default: No arguments
- Parameterized: With arguments
- Copy: Copies another object

- Destructor: Called when object is deleted (~ClassName()).

4. Inheritance
Types:
- Single Inheritance: One base to One derived.
- Multiple: 2 or more base to One derived.
- Multilevel: A to B to C
- Hierarchical: A to B and A to C
- Hybrid: Mix of types

Example:
class A { };
class B: public A { };
class C: public A, public B { };

- Ambiguity: Same member in multiple bases. Resolved using Virtual base class.

Virtual Function: Enables runtime polymorphism.


Example:
virtual void show();

Pure Virtual Function: Must be overridden. Makes class Abstract.


Example:
virtual void show() = 0;

5. Polymorphism
- Compile Time:
Function Overloading (Same name, diff args)
Operator Overloading (Change operator meaning)
- Run Time:
Virtual Functions

6. Templates
- Template = Generic code
- Same function/class for different data types.

Function Template:
template <class T>
T add(T a, T b) { return a + b; }

Class Template:
template <class T>
class Demo { T x; };

Templates can be overloaded and used with multiple args.

7. Exception Handling
- Handle run-time errors without crashing.
Keywords:
- try { code } -> Risky code
- catch { } -> Handle error
- throw -> Raise exception

Multiple catch blocks possible.

Advanced:
- Rethrow: throw;
- Restrict exception: void func() throw(int);
- terminate(), unexpected() handle uncaught exceptions

8. Manipulators (I/O Formatting)


- setw(n): Set width
- setprecision(n): Set decimal precision
- endl: New line
- flush: Flush output buffer
- hex, oct, dec: Set number base
Example:
cout << setw(5) << 10;

9. Streams in C++
- cin: Input
- cout: Output
- cerr: Error (unbuffered)
- clog: Log (buffered)

Formatted I/O:
cout.width(), cout.precision()

Flags:
- left, right
- scientific
- fixed
- hex, oct

Bitfields: Compact memory in structs/classes.


Example:
struct { unsigned int x:4; };

You might also like