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
What is tochararray in java?
Can a static block throw exception?
What is functional interface in java?
What is the indent key?
What is dynamic array in java?
How many types of constructors are used in java?
Why does java does not support multiple inheritance? Explain
Explain about strings in java?
how to create daemon thread in java?
How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?
How do listeners work?
Is array a class in java?
What is the use of singleton?
Can You Have Virtual Functions In Java?
Tell us something about set interface.