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 a class reference?

769


What is nested class?

752


What is parsing a sentence?

758


When to use runnable interface vs thread class in java?

746


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.

1703


What is javac in java?

755


What are abstract methods in java?

876


Explain the difference between comparator and comparable in java?

687


Write a code to show a static variable?

830


How can constructor chaining be done using this keyword?

925


Is java an ide?

724


What is the difference between stringbuffer and stringbuilder class?

804


Is age discrete or continuous?

870


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

755


What is pass by value?

708