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 / bulu
// thread one to print "Hello"
class Thr1 extends Thread
{
public void run()
{
System.out.print("Hello ");
}
}
//thread two to print "how are you?"
class Thr2 extends Thread
{
public void run()
{
try{
Thread.sleep(1);
}
catch(InterruptedException e)
{
System.out.println("interrution occure");
}
System.out.println("How are you ?");
}
}
// main thread
public class BuluThread
{
public static void main(String ag[])
{
Thread t1=new Thr1();
Thread t2=new Thr2();
t2.start();
t1.start();
}
}
//file name should "BuluThread.java"
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
What is dynamic array in java?
What are the java ide's? Explain
How will you load a specific locale?
What is the Scope of Static Variable?
What is flag in java?
What's the difference between comparison done by equals method and == operator?
Can we override private method in java?
Why put method is used?
What is a marker interface?
What is the indent key?
Can java run on google chrome?
Is cout buffered?
What are the advantages of user defined functions?
Can we extend singleton class in java?
What is linked hashset and its features?