Multiple Inheritance in C++ | C++ Tutorial | Mr. Kishore

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi welcome to nourish ad this is he shows and today we are going to discuss about multiple inheritance in law session we have discussed what is inheritance okay and how many types of inheritance models are available today I am going to discuss about multiple inheritance now first of all what is called multiple inheritance it is the process of deriving one class from more than one Base Class okay multiple inherent stands for deriving a new class by using of more than one base class yesterday we have discussed single level inheritance single level inheritance means what it is the process of deriving a class from only one base class just like a derived class with only one base class is called single level inheritance now it is multiple that means what the derived class from several base classes now for example it is the ageless it is the bridge because now both or base classes next here from here I want to do Class C now the C class is having a properties as well as the properties and its own properties also okay now how many base class were participated meet two base classes or how many deliver classes are there only one now this concept is called multiple inheritance now how to conduct multiple inheritance and here one important point we have to discuss what is it okay for example I am going to derive Class C from a xx Class C from B that means both the properties are password to Class V okay now the point is a properties as well as B properties both or pass or to Class C and here we have to remember one important point what it is protected data members already have disgusted we are having private members public members protected members okay for example I am going to use small example sales what is the predicted number and why we need the predicted numbers in inheritance concept we know that public members okay are available to the object and outside also but private number should be accessed only with the number functions of same class now what about protected remember and why we need the protected members in our programming okay just watch here I am giving small example for this so those class student is there ok here mark feels it means now we are having two classes one is student class our other one is marked class now here I want to find out the result I want to find out the result that means it is the third class and this class is derived from which classes both SP one marks class and here suppose student ID here IDs did an name is there next here student marks are there M 1 M 2 M 3 now here I want to find out the total actually we are getting the total from marks no one glitch them do plus M 3 ok here watch it carefully here the point is ID name private numbers suppose M 1 M 2 M 3 are also private members now as C++ hiding as class yes s Percy place based data hiding concept the private numbers of one class are not available or not feasible outside the class that means now we are not able to access M 1 M 2 M 3 directly from result class suppose we are making public then what is the problem it is again is the data hiding concept actually CPP main Dooley's what data hiding when it is public anybody can access that means it is again is data hiding when it is private only that class can access but our requirement is what that class earned next class also that means I want to use the same data members in declared class and derived class in declared class under derived class then you should have to go for protected data members now it is the necessity of protected data members that's why we need the protected data members when a member is protected when data members are protected they are accessible in that class and the immediately derived class it is the most important thing okay whenever the data members are protected they can access within that declare the class and immediately derived class further availability is depended on the inheritance mode means what visibility more suppose if the derivation conducted for example watch this here it is a base class and here protected numbers are there now some protected members are now I am going to derive a class it is the derived class and here the point is these are the protected members and derived class is having ok oblique area protected area you know that now so here I am going to give private for example unprotected once again now what happens suppose you are going to derive this class in public more okay now this crash is derive it in public mode then what happens all the protected members of base class will become once again protected in derived class that's why here public move when public mode is used what happens all the protected members of base class once again they will become protected members in derive occurs that is why they are available for further in hill games now next class it is the next class and he next class also we can use the same protected members next now what about private mode when the derivation is conducted in private mode okay when the derivation is conducted in private mode then what happens now the productive members of this class will become private numbers of derived class it is a point okay whenever the derivation is conducted in private mode now the protected members of this class will become private members of derived class and they can access with the public members all public members of derived class okay they should be accessible with public members of derived class but here on important point they are not available for next class it is not most importantly that's why when a data member is predicted okay now in public mode they will become predicted in derived class and they are ready for further inheritance when protected members are derived in private mode protected members will become private members and then they are not available for next class okay according to this example observe it in private mode they are available for next class in public mode also they are available for next class that means the protected members are used in declared class and immediately derived class the next class availability is depended on private or public model okay that's why we can use the protect members in at least two classes okay we can use the protected members minimum in two classes those classes are what means declared a class and derived class it is what is protected that is why obviously in multiple inheritance multi-level inheritance hybrid inheritance we need the protected data members okay so I protected members are commonly using it multiple inheritance multi-level inheritance hybrid inheritance in common we are going to use that now I am going to show you what is multiple inheritance what is called multiple inheritance okay now my example is going to start with the student class first is this base class and here it is the maths class and here I want to find out the student result that's it oh these two are the base classes and it is the derived class it is the base class it is a derived class that is why we have to construct first of all base classes now I am going to start the program first a common hydrofoils later class ok first I will stream dot H next con you wrote hash okay for here C out and scene and here it is for console input/output operations next suppose class student is there and here int ID and name also there okay in public area I want to read the data wide get student it is for reading the data for both ID and name now see out enter student ID I want to read the student ID and name C in ID uh name okay fine here it is only for inputting the student data next I want to print the student data now put student suppose Here I am going to bring student ID ID equal to ID next and L for next line and next one I want to bring different name name also printed okay now it is a base class okay first of is class student is created next we need another base class called marks that's why I am going to create another one called marks and here marks also base class that is why there is no need of visibility level an inheritance operator here int suppose M 1 comma M 2 comma M 3 please object boxing for subjects again subject and/or subject next we have to read the data first wire get marks okay here I am going to read is a Stu and marks enter three subjects okay see in M 1 M 2 M 3 now I want to print the marks now why put marks now I want to print student marks M 1 equal to okay and here actually it is not required of course but I want to find out the total also then M one candle see out M 2 second subject marks is going to print next third subject marked also M 3 okay here this function is going to reduce a three subject marks it is going to print the three subject marks now I want to find out the resultant okay here I want to find out the result by using of both student and marks class then how it is just a class okay here result class it is the derived class and it is derived from public student comma public marks now what happens student properties as well as marks properties both are inherited to result occurs now student marks student ID number name and marks both or copy to wizard class next here result class is having this phone data that is total next float poweris okay now public section I want to print the result now I want to show the student dessert the so here I am going to write show function okay here first of all I want to find out total equal to M plus M 1 plus M 2 plus M 3 here it is the most important point actually over it totally equal to M 1 plus M 2 plus M 3 actually on 1 M 2 M 3 R what numbers from our class okay here M 1 M 2 M 3 R what data members of which class marks class and they are declared as private ok here there is no visibility mode that's why here they will become private and as per CPP private members are not available in outside ok here the important point is private numbers are not visible outside the class ok and they should be accessed with the member functions of same class only but here I am going to use M 1 M 2 M 3 in the derived class then how to make it then declare protector that's it it is why we need the protector ok now what happens when the data members are protected we can access the data members in DotA class and immediately derived class now result is derived from which one marks that's why it is the immediately derived class now they are available here pasar system is not going to return any error okay it is how to access protected members in inheritance that's why we need the protected data members next power is I want to find out average total my three points why because here we are going for three subject marks three subjects and actually subject wise marks are about integers total also what integer that's why hear what happened in teaser why suppose it is three three also what integer integer by integer always integer but our requirement floating that is why 3.0 now when it is 3.0 it is giving the accurate value next total available average available I want to print this data see out total equal to total endl and see out our is equal to our is finish now dysfunction and class also completed now in this example st one of the base okay it is one of the base class and marks it is another base class and result is the derived now it is varied from how many classes to classes that's why what we have discussed is multiple inheritance needs deriving a class by using off more than one base class okay that's why in multiple inheritance what happened we are going to derive one class from more than one base case now it is now how to call this one okay we need the main function to call this one that's why here I am going for main function already we have discussed in inheritance what happens base class members are possible to derive the class that means now the student details most details are available in present class that's why directly we can create the object of result class now main function it is the main function now I have to create the result class of the result are now R is the word object next first of all what we have to do we have to enter the student ID name then all dot gets to the int function calling and this function is called what happens it is going to read the student ID name finish next we have to read the student marks that's what our dot get marks okay here it is going to read the student a subject marks later are not put student okay this function is going to show the student idea name X are not put marks and this one is going to show student K subject marks and at last I want to show the result where is this in show function that is why our dot show now it is going to find out the total average and it is going to display the total at average that means the student result is displayed now at los geht's eh we will not finish it is what is called multiple inheritance okay thus when multiple inheritance multi-level inheritance and generally in hybrid inheritance we need the protected data numbers thank you thank you for watching [Music]
Info
Channel: Naresh i Technologies
Views: 61,176
Rating: undefined out of 5
Keywords: Multiple Inheritance in C++, Multiple Inheritance, Inheritance, Inheritance in C++, C++ Tutorial, Kishore, Naresh IT
Id: 9koINmwq6a8
Channel Id: undefined
Length: 18min 17sec (1097 seconds)
Published: Wed Apr 26 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.