 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can implement the concept of namespace in C++. Before starting, you can note my information. You can follow or subscribe my YouTube channel that is Sanjay Gupta underscore tech school. You can download my Android app based on programming that is Techimace which is available on Google Play. Now coming onto the topic, here I have implemented the concept of namespace. So namespace basically is a collection of variables and classes which provides a local grouping in C++ programs. So for demonstration, I have included a header file IO stream, then a predefined namespace is used here as TD. So in this demonstration, you will also understand why we are implementing this namespace. So first I have implemented a user defined namespace that is one. So namespace is a keyword and name of namespace is one. It is having two variables A and B. Then inside this, I have implemented a class A which is having a default constructor. Then I have implemented class B which is also having a default constructor. So these two classes are in one namespace. So this is a local group. Then in the same program, I have implemented another namespace that is two. Name of namespace is two. It is also having two variables A and B. Then two classes A and B and along with their constructors. So I have created two namespace and both the namespaces are containing classes and variables with same name. But still this program will work properly because classes are divided into particular namespaces. So without namespace, you cannot implement classes with same name. But if you are implementing namespaces, then in two different namespaces, you can have classes with same names. Now if you want to use class or variable of a particular namespace, then you have to use namespace name, then scope resolution, then class name and then you can create its object. So here one is the namespace name. A is the class name which is defined inside this namespace and A1 is the object. Now this object will be created and its constructor will be executed. Then I am using a name of second namespace that is two. It's class B and B1. So I have just created their objects because they will be calling their constructors. So I am executing this program. You can see the output A in namespace 1 and B in namespace 2. These messages are printed. So first message belonging to namespace 1 and second message belonging to namespace 2. So I hope you have understood how we can access a particular class which is defined in a particular namespace. But if we use this name repeatedly, then it will be difficult work for us. So for that purpose, you can use a keyword that is using then namespace and one. So if you write this statement, then now without using this scope relation and a name of namespace, you can use classes which are available inside this namespace. So I am using namespace 1. So the classes or variables which are defined inside this namespace, I can use them directly. So now you can see I am using its variable also and I am printing its value. So this A variable is having 10. This variable is defined inside one namespace and I am printing it using C out. So this A class and A variable both are available inside one namespace and I am using these variables and classes without using scope resolution. But I have not used namespace 2. So for this, I have to use class name and scope resolution. If I write using namespace for this also, then I can remove this scope resolution and namespace name. So now I am executing this again. You can see the output A is A in namespace 1 is printed then 10 because of this A variable and then B in namespace 2 is printed. So this way I have implemented namespace in this program. So without using keyword, you can also use namespace and with using keyword, you can also use namespace. Now I am talking about this predefined namespace. So you have understood now I think that predefined namespace name is STD and I am using this namespace using this keyword. So it means whatever is available inside this STD namespace, I can use that directly. So now I am commenting it. I am saving the code and I am executing. You will see an error message here in C out. So see out is defined this inside this STD namespace. So to correct this, I can write like this. So if we don't use this STD namespace, then we have to use STD and scope resolution. Wherever we are using C out or scene, now this program will work properly. Sorry with endel I have to use this STD also. Now you can see this program is working properly. It is printing the valid output. So you can see I have used STD 10 times with C out and endel. So this is not a good approach. So instead of using this STD every time, we can use this namespace using this keyword using. So now I hope you have understood all the differences. I have demonstrated you the use of predefined namespace that that is STD. And I have also demonstrated use of namespace by user defined namespaces that are one and two. So implement this in your system so that you can also understand how we can use the concept of namespace which is available in C++. I hope you have understood the concept. Well, if you want to watch more programming related videos, you can follow or subscribe my YouTube channel. That is Sanjay Gupta underscore textbook. Thank you for watching this video.