Multithreading (Parallel Processing):
class Hi extends Thread {
//creating class Hi and make it becomes a thread
public void run() {
for (int i = 1; i <= 5; i++) {
System. out.println("Hi");
try {
Thread. sleep(1000); // pause for 1 second
} catch (Exception e) •}
class Hello extends Thread {
public void run() {
for (int i = 1; i <= 5; 1++) {
System. out.printIn('Hello");
try {
Thread. sleep (1000); // pause for 1 second
} catch (Exception e) (} // when the thread gets interrupted, just ignore it
public class Test {
public static void main(String args) {
Hi objl = new Hil);
Hello obj2 = new Hello();
objl.start();
obj2.start();
}}
Nora Hamad @nora_hamad
عضوة جديدة
يلزم عليك تسجيل الدخول أولًا لكتابة تعليق.
خليك أول من تشارك برأيها 💁🏻♀️