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
Does chrome use java?
Can list have duplicates in java?
What is static synchronization?
Compare overloading and overriding?
What are static blocks and static initalizers in java ?
What does compareto () do in java?
What is the difference between super class & sub class?
Differentiate storage classes on the basis of their scope?
Are arrays primitive data types?
What is the final variable?
Why is the main method static?
What are the different conditional statements?
What do you understand by the bean persistent property?
What is entry in java?
How do you do math powers in java?