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
Can a set contain duplicates?
Explain numeric promotion?
How big is a gigabyte?
What is the difference between size and length in java?
What are the difference between string, string builder, and string buffer in java?
What are serialization and deserialization?
What is integers and example?
How hashset works internally in java?
What is meant by distributed application? Why are we using that in our application?
What is the purpose of default constructor?
What is the purpose of the return statement?
Which data type is a class in java?
Is java hard to learn?
What is abstraction in java?
What is the use of conditional statement?