Assume that you are having a class called Class A it needs to call Class Z as a thread. Therefore you can implement class Z from Runnable interface and implement your code in run().Ex:-
If you start the Thread using ClassZ it runs ClassZ’s run method. Therefore if you have several method in side the class you need to have a variable telling which method you want to run. Thus in here i used code variable to keep the information about the method which i want to run. And also we wrote a method to start the thread called runThread().