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 are static blocks in java ?
What is the function of log?
Can a vector contain heterogenous objects?
What is the relationship difference the canvas class and the graphics class?
Explain about procedural programming language or structured programming language and its features?
What is the maximum size of byte array in java?
Which collection does not allow duplicates in java?
What is break and continue statement?
What is bigger kb or mb?
What are the types of sockets in java?
what is function overloading in java?
What type of language is java?
What about anonymous inner classes in java?
Java is pass by value or pass by reference? Explain
What is stream api in java8?