 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you the concept of nested classes in C++. Before starting, you can note my details. You can connect me by following these information. You can download my app Takimiz based on programming languages. It is available on Google Play. You can search my channel by typing my name on YouTube search. My channel will be available there. You can open it. You can subscribe my channel if you want to follow my videos. Here, various programming related videos and playlists are available. You can improve your programming skills by watching my videos. Now coming on to the topic. In this video, nested class concept in C++ is demonstrated. So first I have included a header file, then sd namespace is used, then I am implementing a class. Sorry, name of class is student and inside class, I have declared two attributes role number and name. Role number is of integer type and name is of character type. Now the concept of nested class says if you implement a class inside another class, then that concept is known as nested class or you can say nesting of classes. So here student class is containing one more class that is date. Now I am implementing date class. I have declared three attributes of date class that are day, month and year, DMY. Now inside its public section, I am implementing first function that is read. It will receive day, month and year from user. Then I am implementing print function. It will display day, month and year on console. And in this specified format, first day, then hyphen, then month, then hyphen, then year. These will be printed on console. Now I am terminating this class. Before termination I am going to create two or three objects of date class like date of birth, date of joining and date of enrolment. So these objects are of date class but these objects are created inside student class. So now student class has five attributes. First is role number, second is name, third is date of joining, fourth is date of sorry third is date of birth, fourth is date of joining and fifth is date of enrolment. So I want to read dates three times. So instead of typing DMY again and again, I have created a class and I have created this date class object inside student class. This is the use of nesting of classes in C++. Now in public section of student class, I am going to implement two functions. First one is read and second one will be print function and then I will be terminating this class. So inside read function, first I am going to receive role number, name of student, then date of birth. For date of birth I am calling dob.read. Now you can see I have just called read function of date class using this dob object. So this is the benefit of nesting class. DMY is DMY variables are read here using CN inside read function. So I have just called this read function. Instead of writing CN DMY, I have called this read function. This is the benefit of nested classes in C++. Now if I want to read date of joining, then simply I have to call doj.read function and same for date of enrollment. I am calling doe.read. So this is complete definition of read function. It is defined inside student class and public section of student class. It is accessing role number and name of attributes which are declared in student class and dob, doj and doe are attributes of date class. Through them I have called read function of date class. Similar to read, I am defining print function. This function will display entered values on console. So this first statement will display role number. Second statement will display name. Then date of birth. For date of birth printing, I am calling print function of date class. Then date of joining. For this I am calling doj.print. Again print function of date class. Then date of enrollment. So doe.print. This is complete definition of student class. So again you can see, first I have created attributes role number and name. Then I have implemented date class inside student class. And I have created three objects of student class. Sorry, date class dob, doj and doe. These objects are created inside student class. So in read function, role number and name are read directly. But date of birth, date of joining and date of enrollment are read with the help of this read function which is defined inside date class. Similarly print function is implemented. Now I am implementing main function. Inside main function I just have to create object of student class. First I am printing a message, enter student details and I am calling read function of student class. So I have called read function of student class. It will read, role number, name, date of birth, date of joining and date of enrollment. So these read functions of date class will be called automatically. So in main function you don't have to call functions of inner class. That is date class. You just have to call functions of outer class. Inner class functions will be called by the functions of outer class. So in this case, date class is inner class and student class is outer class. Now again, cout will print you have entered and then I am calling print function of student class. This is complete definition of this program. Now I am going to execute this. Sorry, I have not used semicolon here. It is printing enter student details. Then first it is asking for role number. So I am entering 22. Then it is asking for name. I am entering Sanjay. Then it is asking for date of birth. So I am entering 22 as day, three as month and 1986 as year. Then it is asking for date of joining. So I am entering 1, 1, 2018. Then it is asking for date of enrollment. Again, I am entering 1, 1, 2018. Now you can see the result. You have entered role number is 22. Name is Sanjay. Date of birth is 22, 3, 1986. Date of joining 1, 1, 2018. Date of enrollment 1, 1, 2018. And dates are printed in date format using hyphen in between day, month and year. So friends, I hope you have understood the use of nested classes in C++. If you don't want to repeat certain attributes, then you can implement those attributes by sorry with the help of a class and you can create that classes objects inside another class. So here this student class is outer class and this date class is inner class. I have created object of inner class inside outer class and functions of outer class are called inside main function and functions of inner classes are linked with outer classes functions. So they will be called automatically when outer classes functions will be called in main function. So this way you can also implement the concept of nested classes in C++. If you want to watch more programming related videos, you can search my name Sanjay Gupta on YouTube. My channel will be available there. Here various programming related videos are available. You can watch them so that you can improve your programming skills. Thank you for watching this video.