Advertisement
Josif_tepe

Untitled

Mar 30th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         MyThread t1 = new MyThread(1);
  4.         MyThread t2 = new MyThread(2);
  5.        t1.start();
  6.        t2.start();
  7.     }
  8. }
  9. class MyThread extends Thread {
  10.     int id;
  11.     public MyThread(int _id) {
  12.         id = _id;
  13.     }
  14.     @Override
  15.     public void run() {
  16.         for(int i = 0; i < 20; i++) {
  17.             System.out.println("Thread " + id + " "  + i);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement