Hello ji , how are you all? this is Love Babbar And welcome to the channel Code help, we have reached our lecture no. 42 , here we are going to talk about object oriented programing We will start from the very basic , in the end we will learn encapsulation ,abstraction ,inheritance and polymorphism in very deep So that when interviewer ask any question we can solve it Lets start ,what is Object oriented programing? I said , this is one type of programing technique ,in which things work around object Lets understand it , this is one type of programming technique ,in which things work around object What is an object? Object is a type of entity , which have two things , 1. state or property , 2. behaviour If we talk about real life , this camera is an object , microphone , lights , laptop, this jug is also an object All these things are considered as an object, we want to use objects in our programs , to bring our program more close to real world why we want to bring our program close to real world? So that, my program readability increases, to increase the manageability, extensibility How? we will learn it, it has many benefits , while learning we will know it For now we know that , this is one type of programing technique ,in which things work around object readability increases, to increase the manageability, extensibility , we have discussed them For example ,you all have played games , there is a hero and an enemy Lets talk about the hero , he has a name There was a game in our time , when we were children "tekken" , his name is Paul He has some health , this is an integer ,70% health is left There was levels , which level Paul he is? ,A, B, C,D in this way I said , he is "a" level Paul , in this way I said some properties ,name, health, level Then I talked about the behaviour , attack It also defence , dance , these are the behaviours of Paul We will see in depth, but for now its ok, when we said object is an entity Have some properties and some behaviours, we have discussed , hero is the object He has some properties and some behaviours, it is becoming clear Coding Ninjas is the largest coding education platform where you can access various type of courses if you are interested in paid courses If you want courses on web dev , machine learning , development , OS, DBMS, DSA in java , Python Then Coding Ninjas is the place for you The best thing about CN is that you get one on one doubt support All your doubts are resolved within 1-2 hours The courses are really well structured If you will work hard , then you will definitely get results The course makers have already cracked big tech companies So you need not to worry about that part The courses are available in both Hindi and English languages You will also get hint videos in every question So , if you want to buy any of their courses Then you can use the link in the description to get the 20% off on all of their courses Thank you Here I said an object has some behaviors and some properties , when we will do it , you will understand it Lets make a class , we will talk more of classes and objects All things will revolve around it Bhaiya you explained object but you didn't explained "class" , what is class? You have learnt something like this , int a; , this is an integer, string str, this is string, char ch, this is character, If here I say , hero's name is Ramesh, so here I made a hero type object As I said you made a variable , str of string type , ch of char type , you made Ramesh of hero type variable So when it comes to class , this is user defined data type You know that there some inbuilt data types int, char, in same way I made my own data type and named it hero This is an user defined data type , I made a custom data type of my own, which i call class We learned about object , this is a type of an entity which has some properties and behaviours One more thing I can say ,object is an instance of class, all things are going theoretically now When we will do implementation you will get it Here we understood that class is an user defined data type , nothing more than that Now Lets implement it , we want to make a class , how we make a class? We 1st write class, its name 'hero' , then we used curly braces, then semi colon , in this way we made a class Hero type one class is made It will have one name , char name[100] ,int health, char level I made a class "hero" , it has some properties Are you getting it. Lets make it more simple Lets say if things were not there , there is only int health If I print it , try to make an object , here I made a class , now I have to make an object hero h1; ,here I made a hero type object Here I defined a class , it has property "health" , in this way created an object Now if I want to see its size, cout<< " size: "<< sizeof(h1)<< endl; What do you think will be its size? If I talk about this object , there is only an integer, it is of 4 bytes Lets run it, it gave 4 When I create this type of objects, it will take the size of its properties Lets understand it once , here class is actually a type of templet there should be a health named integer When I write hero h1, I made an implementation of this . here place some value in health Here we have not put anything explicitly , there should be some garbage value , so this is my object A block got reserved in memory , where data of this health got filled In short, there was an integer , when I made its object , it has taken memory for this integer, when I print it , it gives 4 You might have understood it little bit, this is a templet, when I add data, this is my blue print , here I provided it existence There is health , here we put value in it In this case we have not given any value , a garbage value will be filled here So we understood , we can make class in this way, object can be initialized in this way, it has size according to its properties Lets say if there is no property, it is empty class Then what will be the size? There is nothing, this is empty , this is an empty class , here we made its object, and print its size It should give 0 as answer, I ran it , it gave 1 When this object is created , there is no property, for its rentification ,for your identification it will give 1 byte In case of empty class , your object will get 1 byte , may be you don't get thing in paid courses So take care of this thing, if the interviewer ask you, if your class is empty and I create an object, then how many bytes of memory it will get? You will answer 1 byte, to keep track of it We have understood it, if now someone ask me to create an class or object , we can do it now I can define this class in different file , lets understand it, I went here Make a new class in this file, we named it hero.cpp Here I created the "Hero " class and I put properties that I have told you sometimes ago Now I went back in intro file , remove this class from here The "Hero" class that I have made, I will include itin this code , so that I can use this class in this code For that I have to write , #include "Hero.cpp" Now I have included it, here I can create this "Hero" , if I have not included it, then it will give error It is telling that it is not defined , but if I add here then it will not give the error There are two ways ,1. add this in header file, 2.Explicitly I will create it here, you can do any of the both I do not want to create it indifferent file , I will create it here only We are understanding these things These are my some properties , I put them here There will be health, level , now if I want to print them then how will I do it Comment it Here we have already created h1 , if you want to access it Lets name it Ramesh, if you want to see its health then how will you do it If you want to access these properties/data members You can access them using "." operator ,how? I said , you printed health is "ramesh.health" , that's it In this way you can access this health, why it is giving error , you will understand it in now Again in same way if we want to access "level", here I written " ramesh.level" But why it is giving error I will explain it but 1st run it I ran it, it is telling health is a private member, level is also private member What is private member? Lets understand it, here we are going to talk about access modifier What do you mean by that Bhaiya? There are 3 types of access modifier , 1. public , 2. private , 3.protected In short , whatever data members are here , where you can access them Can you access them inside the class or outside the class , or you will create a child class , what is child class ? we will study it We will know it by access modifier ,1. public , 2. private , 3.protected But here we have not written something like that By default your access modifier in class is private Lets understand "public" first If I made any data member public ,here I will write like this This means all things under public , we can access them anywhere, inside or outside the class If you see carefully , error has been removed from health , level If I have not specified public here, if I put it here Error has been removed from level but it is there in front of health Because under public only level is there , so it became public , and health is private because it is by default private If I write public here, then both will give error , because both became private Public will be the below part If I write it here , error will be removed from both, because have become public, it means you can access them inside and outside the class This is your public Bhaiya , what is private ? Lets see it, if I write here private , this is private , there is level below private Level can be accessed inside the class only These are your properties /data members If you have any function/behaviour , void print () This function can access this level , cout<< level << endl; , it is not giving error instead of being private Here level is private , you used it here,it is not giving any error here But here in level it is giving error When you mark something private ,then you can access it inside the class only not outside the class We have understood this Public means we can access it inside and outside the class , private means we can access it inside the class only Bhaiya protected? I will explain it When I will tell you the child class concept then I will explain you the "protected " concept You should focus on public and private for now, if it is clear to then good. We made everything public ,both the data member and the function became public lets print it, your health is 1 and level is giving this character See carefully we had created "Hero" , we didn't put any value , then these are your garbage value If I want to set them then I can do it We can access them using "." operator , ramesh.health=70, In same way , ramesh.level ='A' Now if I print it, now it gave health =70 and level = A , in starting it was giving garbage value Now you learned how to access , and you also understood the access modifiers Lets move forward , my level has become private Or I say health has become private , and the left over part is public In this case health has became private and lower part has became public , then we can't access health outside this class So it gave error In this case what will we do? We have a concept of getter /setter , we will use it We are going to talk about getter/setter This is not a rocket science , there are some functions inside the class , you can access these variable using those Lets understand how , here we have to make some getter and setter int gethealth(), it gives me the health This is your getter which returns you the health, in same way I made for level char getlevel(), it returns level In same way I made a void sethealth(int h) health= h ; In same way void setlevel(char ch), level =ch; See carefully , there is a variable "health" which is private But I want to access it, I can't do it directly but now I have a way If I do gethealth here , there I can bring it here cout<< "Ramesh health is" <<ramesh.gethealth()<< endl ; So by using this getter you did your work Now I ran it , you can print it using getter So here I replaced it in getter, and I ran it See ,ramesh health is 1 Bhaiya I want to set , we can do it in same way ramesh.sethealth(70), here you used setter I will run it, it gave 70 In starting it was 1, you set it 70, you printed it in line no.46 So we have understood , if any data member is private in your class , like in this case health is private If you want to access it, set or get, you can do it using getter and setter We have understood this getter is simple , we simply written gethealth() ,it did function call By using "." operator It returned health, and I printed it If I want to set, what are the uses of setter ? If you want to put any condition , getter is for fetching/read setter is for putting any condition If I want to check only user A can change it and no other can do it Here you put char name , here I simply checked if(name="A"), only it can change it, it is giving some error Lets ignore it now, but you have understood the logic If I want to put any condition, if I put any password Here I compared using if condition , this password should be like this , then only I will change health There also setter can be used , if you want to use any password or any specific condition So we have understood that setter has many benefit and if anything is marked private Then I can use getter to read it So you have also understood the getter/setter concept Till now you have learned how to make class , object Here we written Hero ramesh , we created a Hero type object Then we learned what are the access modifier? We learned public, private and we will learn protected Then we have seen size and then the get/set concept When we write Hero ramesh then what happens lets understand I written Hero ramesh, hero only contains health and level So when you write Hero ramesh In short what goes behind the scene , in memory you allocate two blocks, one int type which is indicating health And one is your char type indicating level So in memory you have taken 4 bytes for integer and 1 byte for char, in short if I want to print the size of ramesh This is 4 , and this is 1, 4+1 =5 , so it will give 5 bytes Here I write , cout<< "Size of Ramesh is" << sizeof (Ramesh)<< endl; , it will print the size We are thinking it will give 5 as answer, we ran it It is giving 8 in place of 5 If there is two integers then it should give 4+4=8 But here why it is not giving 4+1=5 Here I am setting a homework for you , you have to study about padding , greedy alignment These are the things you will not find in paid courses also So see once what is greedy alignment and padding? If you read it once then this will become clear to you I have not seen this in any online test till now , but I feel that one day someone will ask it , if you know it , then it will be easy for you So you have to do it in homework So till now we have understood class , object, functions , getter/setter, access modifiers also Let me comment out this Here I create an object ,Hero a;, I have created this statically I can do it using dynamic memory allocation , let me show you When we use dynamic allocation , int *i=new int; , we used to create it in this way We got a 'i' named space , we created a new integer which is of for bytes And you stored this address in this ,basically you made a pointer of int type , this memory is allocated in heap We use to call it dynamic allocation in same way if I have to create a Hero using dynamic allocation Then how we will do it? I will create a Hero Type pointer, Hero *h= new Hero;, that's it Hero *b= new Hero Its memory is allocated dynamically in heap In short , this is your Hero type pointer , this is memory allocated in heap having address 710 When you printed its size it gave 8 bytes And this address is stored here , basically Hero pointer is pointing this memory Is it giving any error? no!! If make everything public, no leave it as it is , and print level In this case we will write , cout<< "level is" << a.level << endl; health is private , I will use its getter , cout<< "health is" << a.gethealth()<< endl; In same way if I have to print level, health for this dynamically allocated Hero Things are very simple ,In replace of "a" with (*b) What do you mean by that bhaiya ? Lets me explain you , id U have written b.gethealth() only ,is it right? "b" is my address , if I want to use object then this is lying here Then we have to dereference it , so we dereferenced it 1st , then we made the function call That's why we have written it in this way There is a better way to write it You can write it in one more way ,b-> gethealth(), this is the alternate way So here I have used it Then I ran it , 1st initialize it 1st see it, it is giving garbage value because we have not given anything , health=1 We have created 'b' , it is giving space in garbage value , health=0 If I put some thing explicitly here , b->setlevel('A') ,b-> sethealth(70) In same way , here also a.sethealth(80), a,setlevel ('B') Now if I run it, will it give the same answers It is giving right answers , these are coming similar So there are two way to access its data members , either use '->' or the '*' operator You can access it by using any of them So you have understood it ,how we can create object using static allocation and also using dynamic allocation You have understood both Now we are going to talk about the behind the scenes Lets comment it out Create a Hero ramesh What is happening behind the scenes? What is compiler doing , we are trying to understand this So whenever you create an object , 1st of all one thing is called constructor When we created an object and named it ramesh then a constructor is called What is a constructor ?, let me explain It is invoked during object creation time It doesn't have any return type The constructor we will see now , it also doesn't contain any input parameter Lets make a constructor here , there is a default constructor , we do not need to make one Behind the scene , it will be called like ramesh.Hero() So you called Hero function of ramesh But if we see here , we have not created such function here So when you write a class , then by default a constructor is created by class name If you want then you can create one Whenever you are writing something like this ,Hero ramesh , then a ramesh.Hero() is called As soon as we written at line 38 , this constructor would be called , it is not there now but if we want then we can make it We call it default constructor Here we have seen some properties , it will be invoked during object creation , there will be no return type , no input parameter I want to write it ,there is no return type , name will be same ,Hero(), we written the constructor We have made our own constructor , simply put , cout<< " Constructor called "<< endl; Here I cleared it If you see carefully We have just written one statement, we have create the object statically whenever you will write Hero ramesh like this Then this type of call will go, so this function/ constructor should be called I ran it , see carefully constructor has been called Lets understand it once again , 1st let me print "Hi" so that I can understand what is happening , and after that I will print "Hello" We are learning things in very depth , flow wise which is called 1st and which is called later, I ran it 1st "hi" is called , it means 1st line no.44 is executed Then at line no.45 you have written Hero ramesh , then constructor is called Then you came to line no.46 , where Hello is printed So we have understood it properly Lets remove these lines So we have understood if we made this type of object ,then our this constructor will be called If I have created it dynamically Hero *h= new Hero , then ran it Constructor is called two times , one time for static and one time for dynamic Either you allocate statically or dynamically in both case same constructor will be called We have understood these things , if I write it in this way then also it will remain same , I run it It is giving the same thing So you can create in both the ways Now we learned to make a constructor of without argument , "default argument" . Once we written this constructor , the inbuilt constructor will be removed automatically , it will be not called So now I will make you understand the parameterized constructor The constructors which will contains some parameters parameterized constructor So I will make some constructors with parameters , Hero( int health) ,health=Health; It is looking little bit confusing , we are not getting it When I write health=Health ,what is this? Lets understand this ,here we will learn one more thing , " this keyword" So when this type of situation comes , the input parameter and the data member have the same name then you will get confused If you remember variable scoping , as we are access health here , we are talking about the "health" ,whose scope will be nearer This health has scope nearer In short, this is a block health, you filled the value within itself If there is '3' , you put '3' again within itself Our line no.19 is doing this, but we want to fill the value of health at line no.18 to the health at line no. 8 This is an object "ramesh" , this is a block inside ramesh named health This is health which has came as input in my function I want tom put its value in this block but what is happening We are putting its value within itself according to my implementation Here , there is many benefits of "this keyword" ,we will understand what is this? I said , whatever is your current object , in this case ramesh is the current object Its address is stored in this It means there is a block , its name is 'this ', it is containing the address of ramesh This means it is a pointer, which is pointing to your current object What is current object? if we make a call ,ramesh.gethealth(0, then my current object is ramesh Here I am creating ramesh as na object , so ramesh's address will be stored in this pointer If I say to put this block's value in this block Put this health in ramesh's health, how will we find ramesh's health By using this pointer , this-> health, it is pointing to this block You have put this health here, in this way you used this parameter this ->health =Health;, you removed the confusion using "this" keyword When I said this is a pointer , then how will we verify it ? I printed ramesh's address here , Here I printed this Then I ran it , construction call here we have to give a value , because it is a parameterized constructor So here in input I gave 10 as input , lets run it So this is "this" value , and this is ramesh's address So both are same , now you understood when I say this means , it stores the address of current object This is the address of current object , and "this" is also containing this So if you want to access data member/function of current object , then you can use "this", because this is a pointer to the current object We have understood it So when I say I want to create a parameterized constructor , we create it statically like this and dynamically like this Lets run it , it is working properly In this way things are working , I can make this in one more way I made one more constructor , and passed level along with health Here I written , this -> level =level So when I say this->level , we are talking about object level , when I say this level , then we are talking about this level So we copied input level in object level If I have to create it here , Hero temp(22, 'B') Lets run it , it is working properly , there is no problem For your satisfaction lets call its parent function, ramesh.print() In same way I said h->print(), in same way I said temp.print() Now lets call it, let me clear it Then I ran it , there are some garbage value ',' , ' ' ,'b' are printed Because our print() function only prints level So we have understood how dynamic allocation is done , what is this keyword, what is default and parameterized constructors If I make differences in parameterized constructor , then I can make multiple constructors Whenever I make one constructor ,then inbuilt constructor will not exist Lets say I remove default constructor ,this doesn't exist Then will there be a inbuilt default constructor? no!! Lets run it , if I simply write here , create Hero tt; , will it be created? For this non parameterized constructor will be called but there is no nonparameterized constructor There are constructor of two parameters ,there will be no default one , it gave error So when you write any constructor implementation ,then no default constructor exist here when you write any constructor implementation ,then no default constructor exist here Till now you have understood two things , 1.what is default constructor ,2.parameterized constructor Lets move forward to another type 3.Copy constructor There is constructor so it is talking about object creation And you are trying to copy object So I have an object which I want to copy Lets comment it out ,I made a Hero suresh , why it is giving error? Because we have removed the default constructor , lets bring it back Here I simply write ,cout<<"Single constructor called"<<endl; It is working properly , suresh.sethealth(70), suresh.setlevel ('C') If I want to do it in single line then I will use parameterized constructor Hero suresh(70 ,'C'), remove this Lets move forward , I have created this object at line no. 53 Then I made one more object , Hero ritesh (suresh) In short here what I said that ritesh.health=suresh.health, and ritesh.level=suresh.level I have done the same thing using this line ,lets replace it with 'R' make an object of named 'R' , copy all data members with value of suresh I replaced this whole thing with this line If I remove and print 'R' , R.print() , here we will print suresh Here we will print two things ,1.cout<<"health"<<this->health<<endl cout<<"level"<<this ->level<<endl Now I run it , this is my print function , here I created suresh , lets make it 's' then printing it, then I created 'R' and printed it Lets run it , for this I have given 70, C as input , and if you see carefully in 'R' also there is same value So when I write this type of statement at line no.58, then my copy constructor is called What is copy constructor ? here we have made 3 things 1.simple constructor ,2.two parameterized constructor , so when you write a class Then an inbuilt one more copy constructor is generated, no need to do anything What is happening basically here ? at line no. 54 , we have created 'S' Hero There are two things , health and level then at line no.58 , you made a 'R' named Hero there is also two thing 70 and C , health and level when you written using this syntax , pass 'S ' here , then your copy constructor is called These values will be copied here In this way , copy constructor did its work Bhaiya can I write my own copy constructor ? Yes , lets write it Hero() , here you will pass hero type object this->health=temp.Health, this -> level= temp.Level So you copied these things , there is little mistake ,why it is giving still error? If I put & here , then what happens , it becomes right But if I remove & from here , then what will happen? Then it gives error , let try to understand it Here I made a constructor , I passed an object of Hero type See carefully, when I call it here , Hero R(S) This is pass by value , in pass by value a copy is formed So this temp is a copy , here you tried to make a copy of S When you try to make a copy , then you call copy constructor, and this is a copy constructor Again you will come to temp, then copy will be formed here , so you got trapped in an infinite loop To escape from it, you will use pass by reference , then you will not send the copy , you will send the 's' basically you indicated same memory with 'S' and 'temp' In this case you directly came here and did the work So if you use pass by value in copy constructor , then you will be trapped , and if you use pass by reference then you can escape it Are you getting the logic , if I have did pass by value Then I have been trapped , lets understand it again this is my copy constructor , whenever I will try to copy object, then I will call this copy constructor Here I passed temp, make one 'R' type object ,Hero R(S) You put S here , it has been passed by value This is S , here copy is made , we made temp and tried to copy it So copy constructor will be called , again it will try to take temp , then again it will call copy constructor Again it got trapped , so I will pass by reference to escape it Location will be same , I can call it 'S' , or temp , in this way you solved this problem If someone ask you , why you pass by reference ? Then you know it, if I will not pass it by reference , then it will be trapped in infinite loop This is why it is showing error here If now I try to run it , it is working properly How I can know that copy constructor has been called here It is simple , print it and cout<< "copy constructorcalled"<<endl; I ran it, one more thing keep in mind When you write your own copy constructor, inbuilt default constructor will no more exist here Till now you have learned simple constructors are of this type , types of parameterized constructor , types of copy constructor There is one more concept " Shallow and Deep copy " Till know we have seen copy constructor But there is one thing , that your default copy constructor , it implements shallow copy What is shallow copy ? we will understand it now In starting we have written char name here Then I will initialize here whenever my object will be created , name=new char[100] If you think to write in this way , it is not a good practice We allocate in heap , there more space is available So we allocated this array at line no.16 dynamically In this way I allocated it Here I will set a setter , void setname(char name []) You will copy it in your current pointer, strcpy (this -> name, name ) We got it , you set it If I remove it from here , and create an object , Hero hero1 hero1.sethealth(12), hero1.setlevel('D') Here create one name , char name[7]="Babbar" Here you set the name, then you printed hero1 By this I am going to show you shallow copy concept you created hero1 , and put some values in it , then you printed it Then you ran it , if you see carefully you can write it in a better way in this way and I ran it Now its looking more good , you printed hero1 name = Babbar , health=12, level=D In same way if we use copy constructor create one more hero Then you have to comment out your own copy constructor , now I can use default copy constructor Hero hero2 (hero1) , here default copy constructor will be called One more way is , Hero hero2 =hero1, in both case copy constructor will be called In this way we created hero2, and printed it Lets run it , both are exactly same hero1. name[0]='G', hero1 .print(), now what will happen? It became 'Gabbar' , lets print hero2 hero2 name also change to Gabbar , we have only change hero1 name then how hero2 name got changed Here you will understand the shallow copy concept We created hero1 and printed it, it gave Babbar , then we copied hero2 and printed it, it gave , Babbar Then we changed hero1 name to Gabbar , then we printed hero2 ,now it is giving Gabbar When I said that default copy constructor do shallow copy , now I will explain you the shallow copy concept As we said name is a character array , which contain Babbar This is my hero1 , there are 3 things ,name , health, level This is hero2 , there will be also 3 things , name , health, level If we see the code carefully , your name is a char type pointer In short, the address inside this box , lets say its address is 710, then 710 will be stored You copied all values , so here you have copied 710 , so when you said to change hero1 name , make it 'G' When you say to print hero2 , it will go to 710, there is Gabbar In short, in shallow copy you are accessing the same memory by two names Its name is hero1 and also hero2 Memory is same That's why it is giving error here, if here I have done deep copy What is deep copy? One more copy of this will be formed Bhaiya how deep copy will happen? Now I will write my own copy constructor , where I will do deep copy Default copy constructor do shallow copy , but I want to do deep copy So I will form an new array, char *temp=new char [strlen(temp.name ) Here you did + 1, because there is null character also Here we made a new character array I said to copy, strcpy(ch, temp->name) this->name=ch So what I did here , I said this is hero1 , there are some values , name , health, level The address is 710, Babbar tyhen /0 character In same way , create hero2 , in which copy hero1 this is name , health, level So this copy constructor will be called here, so you made a new array , and copy these values in it Assume it address is 810 , so you put 810 here There is 810 and here 710, so in case of deep copy you made entirely different array If I ran my example with deep copy Earlier it was Babbar , now also it is Babbar So we have understood the difference between deep and shallow copy In deep copy you simply sent the address and setter , in shallow copy you made entirely different array So the concept of deep copy and shallow copy must be clear to you If you need documentation to understand , then go to code studio , I will give the link in the description You can read all of these here You will be able to understand it There are very good examples It will become more clear to you You have understood deep copy and shallow copy concept Lets move forward to "copy assignment operator" We are talking about "=" operator , lets say two objects are already created One is hero a( 10, C) ,hero b(20 ,B) I write a=b , then what will happen in this case There is 10 , this is my health , level=C This is b, There is 20 in health, level=B When I write a =b , then these will be copied here In short, a.health=b. health, a.level=b.level, a. name =b. name In this way we represented these statements by this statement Object is created already , after that you want to copy , then you will use copy assignment and copy in this way Let me show you , it is containing Gabbar and it is containing Babbar For clarity clear it , remove it So in 1st object there is Gabbar and in hero2 ,there is Babbar hero1 = hero2 In short I said copy these values here let run it , now we didn't got the answer , because we have not printed it ,lets print them again Lets run it , earlier it was Gabbar and Babbar, copy hero2 to hero1 , copy these values here !st it was Gabbar , now it is Babbar In short we replaced all these statements by this statement, so we have understood it Now we are moving to next concept , "destructor" , very simple It is for deallocating memory it is used As your objects becomes out of scope, then destructor is called ,and it free the memory Lets remove them , if here i have made a hero object Hero a Lets say this function has ended here , its scope has ended So destructor will be called , this memory will be freed Destructor work is to deallocate memory In same way during the formation of class , destructor is also created automatically, you can also create it Destructor also has the same name as class It also has no return type It also has no parameter There are two more things , lets understand them As here we allocated statically , how can we do dynamically Hero 8b =new Hero (), so dynamically I created a Hero Destructor will be created automatically but if i want to create then I can do it It is resembling like constructor Then how we will find the difference between constructor and destructor We use " ~" sign , ~Hero (), in this way you written destructor cout<< "Destructor bhai called" <<endl Then I ran it , lets remove these parts You have written only these two statements , and you ran it For this simple constructor is called , then for this Then destructor is called once , it should be called for two times Why it is called only one time? so we have to understand one more thing The object you form by static allocation , for them destructor is called automatically Hero a, for this destructor will be called automatically But for this you have to call destructor manually delete b; , then I ran it , see two times destructor has been called So for dynamically allocated objects you have to call destructor manually So you understood the destructor concept As I have said you constructor for any object is called once in same way destructor is also called once for each element during its destruction time As we write our own destructor here , inbuilt destructor will be removed Lets talk about some homework , you have to study about const keyword , how we use it in object creation Hoe can you create const type functions And you have to also see initialisation list These concepts will take 5-10 minutes to cover , this is for homework How can we use it in members data type How can you make function const, s o you have to see it once Lets move to our next topic , static keyword Lets say this hero class has one more data member timetocomplete But bhaiya it doesn't depend If there is a hero or enemy, time to complete , assume you have to complete in 1hour or 5 hours , timetocomplete tells you how much time is left Then it is independent of hero and enemy Basically it is a type of property which do not depend upon hero and enemy If I say hero's timetocomplete is this , then enemy will also have the same , all the objects in that particular game will have the same timetocomplete So here we will use static keyword, it create such type of data member which belongs to class It means to access it you do not need to make object If I have not made any object then also I can access this timetocomplete How? lets understand , lets replace it with previous things I have not made any object , but I want to access this static member, 1st i need to make it static static int timeToComplete, 1st we have to initialize it If you want to initialize it , then where you will do it , you will initialize it outside the class how? , int Hero::timeToComplete=5 1st the data type , there it is int, then class name it is Hero, then you put:: Then you put field name then the value ,so this is the syntax I said there is no need to create an object to access it, so if I want to print it cout<<Hero::timeToComplete<<endl; Lets run it , see you printed it without creating an object, this is speciality of static data member If I try to access it by making object, Hero a , cout<<a.timeToComplete<< endl; Lets run it, it ran properly but this is not recommended because it doesn't belongs to object ,it belongs to your class Try to access it in this way So you need to understand this , lets do experiment here Hero b; b.timeToComplete =10, and printed it 1st it gave 5, again 5, then you updated after b , so it is giving 10 in both the cases Logic wise it is running properly but try to access it in this way , so you have understood static member Lets talk about static functions There are some properties ,let me tell you there is also no need to create an object you can simply call it using class name It doesn't have this keyword , because this keyword is pointer to current object but here there is no object Lets try to add here , I made a static function , static int random() , it can access only static members cout<< this->health<<endl;, if I print it here I have not created any object, we are just calling random function There is no this ,so I removed it and ran it invalid use of member health in static member function, it can access only static members So it can't access health , level ,name If now I print this , it is giving error , in static int random, I added this static member And we have to return it once I have already printed it here at line no.86 , so I ran it It is running properly , so we understood this So in this lecture we have seen what is class ? Object and how it is created , what are there data members How there behaviour / functions are made , we learned about access modifiers Public , private, protected we will learn in next lecture We talk about static allocation and dynamic allocation Constructor , simple, default , parameterized Copy constructor , then we talk about copy assignment operator We have seen destructor , static allocation and dynamic allocation I have given you some homework in starting , padding, greedy alignment When we have seen destructor , then we talked about deep copy and shallow copy There was a const keyword , I gave it in homework , const functions also , initialization list After that we talked about static member functions , we studied static data members and static functions In case of OOPS we have learned so many things in this lecture , you have understood things After this we will talk about the four pillars of OOPs inheritance , polymorphism , encapsulation ,abstraction , we will talk about that in next lecture Whatever we have studied, all theory is available here on code studio , we can read them you will understand them I will add the link in the description , that's it for this video. 5:17am Lakshay is also there , he is shooting your OS videos , Lakshay bhai say "Hi" , "Hello" , hard work is going on in the morning That's it for this video , we will meet in the next video ,Bye bye