Creating a Thread by Extending Thread class

  package com.company;


class MyThread1 extends Thread{
@Override
public void run(){
int i = 0;
while (i<40000){
System.out.println("My thread is runing");
System.out.println("I am happy");
}
}
}
class MyThread2 extends Thread{
@Override
public void run(){
int i = 0;
while (i<40000){
System.out.println("Thread2 is good");
System.out.println("I am very happy");
i++;
}
}
}


public class tuts {
public static void main(String[] args) {
MyThread1 t1 = new MyThread1();
MyThread2 t2 = new MyThread2();
t1.start();
t2.start();
}
}

Comments

Popular posts from this blog

Constructors from Thread class in Java