1. topics (Apna College)

Reusability

create classes => define their properties & functions => create objects out of it
properties of an object of a class can be altered using dot operator
shallow copy is problematic in case of dynamic memory allocation
-----------------------------------------------------------------------------------------------------------

1. objects- entities created out of a class
2. classes
- blueprint
3. properties/ attributes
4. functions/ methods/ member functions
-------------------------------------------------------------------------------------------------------------

5. constructor- function with no return type, called only once at initialization of object

                      - non-parameterized, parameterized, copy

                        - non parameterized are automatically called

                        - parameterized aren't called automatically

                       - in parameterized constructors, we set objects prop to values reflected by                                 passed parameters in constructor....to show obj prop we can use THIS                                     POINTER (e.g., this->name)

                       - these functions are named same as of class

                      -constructor overloading (creating multiple constructors inside a class with the                         only difference in each of them being the no. of parameters required by each                         as arguments)

                        - constructor overloading is an example of polymorphism

                        - default copy constructor to copy properties of one obj into another, e.g.,

                         student s2(s1);

-------------------------------------------------------------------------------------------------------------

6. Destructor- used to de allocate memory

                 - delete only statically allocated memory for variables, so for the dynamically                            allocated one we have to ourselves use delete keyword inside destructor to de                         allocate that dynamic memory

                 - has same name as of class

                 - created similarly like a constructor just that we need to add an extra ~ symbol                     before function name

                 - it is also called automatically whenever object goes out of scope, i.e., it isn't                           used at that point of time in our code

---------------------------------------------------------------------------------------------------------------

7. Access modifiers, setter & getter functions

-----------------------------------------------------------------------------------------------------------

8. encapsulation- wrapping up of data and some member functions together in a single unit                             called class

                        -data hiding (using private or protected access modifiers)

-------------------------------------------------------------------------------------------------------------

8. Deep Vs Shallow copy

e.g., below is one of the differentiating factor b/w the 2 on the basis of a custom copy constructor

shallow-

deep- 

------------------------------------------------------------------------------------------------------------

Stack memory (allocated beforehand only , like in compile time, in STACK) 

                                        VS 

dynamic memory allocation (allocated at runtime in the HEAP)

-----------------------------------------------------------

dynamically creating a pointer variable in heap and setting value to it by dereferencing-

e.g.,

float* x;

x = new float;

*x = 5;

---------------------------------------------------------

dynamically Allocated memory (i.e., using  new keyword)

is deallocated dynamically (using delete keyword)


delete ptr means delete the memory to which ptr is pointing to, and not that ki ptr ko delete krdo

----------------------------------------------------------------------------------------------------------

9. Inheritance 

base class, derived class

there are 3 modes of inheritance- private, public, protected.

below is an example of a public mode inheritance-

whenever memory of an obj is allocated, then firstly constructor of base class is called and then the derived class constructor is called...

VS

whenever memory of an obj is de-allocated, then opposite happens

---------------
for calling a parameterized parent class constructor in derived class below method is used-

---------------------

MODES OF INHERITANCE -

private member function and properties of base class can't be inherited.

public   ,,            ,,              ,,       ,,          ,,      ,,       ,,     are inherited in every case

if we want to access private prop only for inheritance then, we make them protected

-----------------------

TYPES OF INHERITANCE-

Single level inheritance

Multi level inheritance- grandparents wagarah se aari inheritance to the child

Multiple inheritance- 2 parents 1 child


Hierarchal inheritance- 1 parent 2 children

Hybrid inheritance
----------------------------------------------------------------------------------------------------------

10. Polymorphism⭐

ability of object to behave in diff ways depending on context in which it is used

means obj can decide which constructor to call based on arguments passed at time of initialization

Compile Time Polymorphism- e.g., constructor overloading, fn overloading, operator overloading

overloading- defining 2 same name functions with diff arguments within a same class

overriding- overriding is dependent on inheritance, it means when parent & child contain same fn with diff implementations. toh object jis class ka hoga us class ka fn override krdega

Runtime Polymorphism- e.g., fn overriding, virtual functions

------------------------------------------------------------------------------------------------------------

11. Abstraction -hiding unnecessary details & showing imp only

                         - can be implemented using access modifiers

                         - vs data hiding

                         - can also be implemented using abstract class
                         - can't be instantiated & meant to be inherited
                         - uses pure virtual functions

-------------------------------------------------------------------------------------------------------------

12. Static keyword

static variables:

                       - static lagane se vo chiz ab stack ke deallocation process mein delete ni                                  hoyegi

                       - static lagane se vo prop ya method har obj ke liye same hoga

static objects

                       - static keyword se ye obj ka scope bada ho jayega mtlb agar kisi if mein bani                         bhi thi ye obj toh ab ye if ke just bahar ke badle main ke end mein destruct                             hoyegi

-----------------------------------------------------------------------------------------------------------

Comments