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 a class reference?
What is nested class?
What is parsing a sentence?
When to use runnable interface vs thread class in java?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
What is javac in java?
What are abstract methods in java?
Explain the difference between comparator and comparable in java?
Write a code to show a static variable?
How can constructor chaining be done using this keyword?
Is java an ide?
What is the difference between stringbuffer and stringbuilder class?
Is age discrete or continuous?
Is it possible to use Semaphore/ Mutex in an Interrupt Handler?
What is pass by value?