public class MethodAndThread extends Thread {
public void run() {
try {
for (int i = 0; i < 5; i++) {
System.out.println(i + ":" + Thread.currentThread().getName());
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println(e);
}
}
public static void main(String[] args) {
MethodAndThread mt1 = new MethodAndThread();
MethodAndThread mt2 = new MethodAndThread();
//Thread1
// mt1.start();
//Thread2
//Both threads will run simultaneously
// mt2.start();
//calling run() method
mt1.run();
//calling run() method
//method will run one after another
mt2.run();
}
}