//Creating a thread(1st way)...
class ThreadTest3
{
public static void main(String args[])
{
Threads1 obj1 = new Threads1("Hello"); //parameter is passed to make sure that this particular thread is running
Threads1 obj2 = new Threads1("World"); //Here pass a string but in 2nd way pass object of implemented class
obj1.start();
obj2.start();
}
}
class Threads1 extends Thread //directly inheriting the Thread class
{
String msg;
public void run() //this is the run method available in class- Thread
{
for(int i=0;i<10;i++)
{
System.out.println(msg);
}
}
Threads1(String m)
{
msg= m;
}
}
No comments:
Post a Comment