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
When will we prefer to use set and list in java and why?
Why does java have two ways to create child threads?
Which package has light weight components?
Can we have more than one package statement in source file ?
How to sort a collection of custom Objects in Java?
What is the difference between variable declaration and variable initialization?
What is difference between == equals () and compareto () method?
List the interfaces which extends collection interface?
What are the two types of streams offered by java 8?
What is array command?
What is the difference between heap and stack memory?
How does map works in java?
What do you mean by inner class in java? Explain
What are the different types of sorting in java?
Which sorting algorithm is in place?