multithreading by extending threads

PHOTO EMBED

Sat Jan 20 2024 09:14:11 GMT+0000 (Coordinated Universal Time)

Saved by @E23CSEU1151 #java

class P extends Thread {
    @Override
    public void run() {
        try {
            for (int i = 1; i <= 5; i++) {
                System.out.println("akhil");
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            // Exception handling code (empty in this case)
        }
    }
}

class D {
    public static void main(String[] args) throws InterruptedException {
        P r = new P();
        r.start();  // Starts the thread

        for (int i = 1; i <= 5; i++) {
            System.out.println("tanishq");
            Thread.sleep(1000);
        }
    }
}
content_copyCOPY