InterviewSolution
Saved Bookmarks
| 1. |
What are the two ways of implementing thread in Java? |
|
Answer» There are basically two ways of IMPLEMENTING thread in java as GIVEN below:
Example: class MultithreadingDemo extends Thread { public VOID RUN() { System.out.println("My thread is in running state."); } public static void main(String args[]) { MultithreadingDemoobj=new MultithreadingDemo(); obj.start(); } }Output: My thread is in running state.
Example: class MultithreadingDemo implements Runnable { public void run() { System.out.println("My thread is in running state."); } public static void main(String args[]) { MultithreadingDemo obj=new MultithreadingDemo(); Threadtobj =new Thread(obj); tobj.start(); } }Output: My thread is in running state. |
|