WAP to create multiple threads (implementing runnable interface)

3 years ago
OOP Java

package runnable;

class A implements Runnable{

public void run() //public keyword to be written

{

int i;

for(i=1;i<=10;i++)

System.out.println("Thread A "+ i);

}

public void fun(){      //another method declared

System.out.println("Hello");

}

}

class B implements Runnable{

public void run()

{

int i; for(i=1;i<=10;i++)

System.out.println("Thread B "+ i);

}

}

public class ABC {

 

public static void main(String[] args) {

// TODO Auto-generated method stub

Thread t1=new Thread(new A());

Thread t2=new Thread(new B());

t1.start();

A a=new A();     // to access fun method we have to create class A's ref. variable

a.fun();

t2.start();

}

 

}

         

0
Bijay Satyal
Nov 3, 2021
More related questions

Questions Bank

View all Questions