Write java code to print "Hello how are you"
Thread1 should have "Hello"
Thread2 should have "how are you"
both the threads should start at the same time

Answer Posted / ratan kumar

class ThreadTest1 implements Runnable
{
public void run()
{
System.out.print("Hello ");
}
}
class ThreadTest2 implements Runnable
{
public void run()
{
System.out.print("How are You");
}
}
public class Test {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException {
Runnable r1=new ThreadTest1();
Runnable r2=new ThreadTest2();
Thread t1=new Thread(r1);
Thread t2=new Thread(r2);
t1.start();
t2.start();

t1.join();
t2.join();
}

}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is tochararray in java?

494


Can a static block throw exception?

649


What is functional interface in java?

509


What is the indent key?

585


What is dynamic array in java?

520






How many types of constructors are used in java?

532


Why does java does not support multiple inheritance? Explain

545


Explain about strings in java?

612


how to create daemon thread in java?

600


How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

535


How do listeners work?

503


Is array a class in java?

501


What is the use of singleton?

506


Can You Have Virtual Functions In Java?

581


Tell us something about set interface.

555