In java, stop() method kills/terminates the currently executing thread.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class A extends Thread { public void run() { for (int i = 1; i <= 5; i++) { if (i == 3) stop(); System.out.println("A" + i); } System.out.println("Exit from A"); } } public class TestMain { public static void main(String args[]) { A a = new A(); a.start(); } } |
Result
1 2 | A1 A2 |
Description: in the above program, when