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
Can we declare an array without size in java?
What type of language is java?
When can you say a graph to be a tree?
What is void data type?
Explain what is Marker interface?
why java does not support unsigned keyword?
Can we start a thread twice in java?
what is predefined function in java?
What is the purpose of the file class in java programming?
State the significance of public, private, protected class?
What is method overloading in java ?
What is the difference between int and integer in java?
How to perform linear search in java?
Explain an algorithm to find depth of a binary tree.
What are the difference between composition and inheritance in java?