 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can apply multi-threading by implementing the enable interface in Java. Before starting you can subscribe my youtube channel by clicking on the link which is available at bottom right corner of this video. You can download my app Takamis that is available on Google Play. You can connect with me by following these details which are available in front of you. Now coming on to the topic. Java provides two ways to apply multi-threading. First one is by inheriting thread class and second one is by implementing run-able interface. So this is the code which is implemented with the help of inheriting thread class. Here three classes first, second and third are defined and all three classes are inheriting thread class. Whenever we inherit thread class we have to override run method so you can see that all three classes are implementing or overriding run method and providing some set of instructions for execution. After defining definitions of three classes test classes implemented which is defining main method inside main first second and third all three classes are creating their objects and start methods are called using their objects. So f.start, s.start and t.start. So start method is responsible for calling run method. So all three calling statements of start will internally call run methods which are defined inside first second and third classes and the execution of all three run methods will happen simultaneously. So this is simple demonstration with the help of inheriting thread class. Now there is a simple problem while implementing multi-threading by inheriting thread class. Suppose definition of class first is like this class first extends student that is first class is already inheriting a class. Now if you want to apply multi-threading on this class then you have to inherit another class that is thread and that is not possible in java. In java you can only inherit one class you cannot inherit two classes at same time. So the solution of this problem is an interface that is runnable. So now this is the scenario class one extends student. Suppose your class name is one and it has already extended or inherited student class and you want to apply multi-threading on it. So instead of inheriting thread class you can implement runnable interface and runnable interface also provides run method you can define its definition here. So friends whenever you can't implement or you can't inherit thread class for multi-threading you can implement runnable interface so that multi-threading can be applied properly. So I hope you have understood the difference between inheriting thread class or implementing runnable interface. Both are same but there is a slight difference between them if you have not inherited any class then you can use thread class or you can use runnable interface but if your class has already inherited a particular class then forcefully you have to implement runnable interface. Rest of the definitions are same so here one two three three classes are defined and all three classes are implementing runnable interface and run method is defined. Now for calling purpose demo class which is having main method inside main object of one two and three classes are created and they are linked with object of thread class. So thread class object t1 is created which is accepting f as an argument and then t1.start is called. This is because run method is called by start method and start is available inside thread class. So here we have to create object of thread class then we have to link it with the class in which run method is defined. So t.start will call run method of one class. Similarly t2 will call start method and start will call run method of two class and same with three class. So these start methods internally call run methods now I am going to execute this code I am executing demo.java so you can see the output output for first thread is printed first then second thread and then third thread. So output of multi-threaded program will be different each time whenever you execute that code because there are multiple processes or sub threads available in a single code and which thread is executed first by the CPU that we can't predict. So in case of multi-threaded program if output of more than one execution are different then don't panic it will happen while you are implementing multi-threaded concept in java. So I hope you have understood the difference between thread class inheritance and implementation of renewable interface. So you can implement both the concepts so that you can understand the working of multi-threading in java. These are simple demonstration if you want to watch more videos related to multi-threaded programming you can watch other videos which are available on my youtube channel you can subscribe my youtube channel if you want to watch programming related videos. Thank you for watching this video.