Java program to create a class by extending the thread class and use its methods.
Below code is to create a class by extending the thread class and use its methods:
class A extends Thread
{
public void run()
{
for(int i=0;i<3;i++)
System.out.println("Thread 1 is executing");
}
}
class B extends Thread
{
public void run()
{
for(int j=0;j<3;j++)
System.out.println("Thread 2 is executing");
}
}
class C extends Thread
{
public void run()
{
for(int k=0;k<3;k++)
System.out.println("Thread 3 is executing");
}
}
class Mainthread
{
public static void main(String[] args)
{
A t1=new A();
System.out.println("t1 priority = "+t1.getPriority());
t1.setPriority(Thread.MAX_PRIORITY);
System.out.println("After setting t1 priority"+t1.getPriority());
System.out.println("Name is "+t1.getName());
t1.setName("MY THREAD 1");
System.out.println("t1 after setname "+t1.getName());
B t2=new B();
System.out.println("t2 priority = "+t2.getPriority());
t2.setPriority(Thread.MIN_PRIORITY);
System.out.println("After setting t2 priority"+t2.getPriority());
System.out.println("Name is "+t2.getName());
t2.setName("MY THREAD 2");
System.out.println("t2 after setname "+t2.getName());
C t3=new C();
System.out.println("t3 priority = "+t3.getPriority());
t3.setPriority(Thread.NORM_PRIORITY);
System.out.println("After setting t3 priority"+t3.getPriority());
System.out.println("Name is "+t3.getName());
t3.setName("MY THREAD 3");
System.out.println("t3 after setname "+t3.getName());
System.out.println("thread 1 is executing");
t1.start();
System.out.println("thread 2 is executing");
t2.start();
System.out.println("thread 3 is executing");
t3.start();
}
}
Thank You.