Online Java Compiler By
JavaTpoint.com
public class JavaInterruptedExp extends Thread { public void run() { for(int i=1;i<=3;i++) { System.out.println("doing task....: "+i); } } public static void main(String args[])throws InterruptedException { JavaInterruptedExp t1=new JavaInterruptedExp(); JavaInterruptedExp t2=new JavaInterruptedExp(); // call run() method t1.start(); t2.start(); System.out.println("is thread t1 interrupted..: "+t1.interrupted()); // interrupt thread t1 t1.interrupt(); System.out.println("is thread t1 interrupted..: " +t1.interrupted()); System.out.println("is thread t2 interrupted..: "+t2.interrupted()); } }
Output