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 sorting algorithm in java?
What do you mean by constant time complexity?
What is the difference between Java1.4 and Java1.5
What is an example of a keyword?
What is the difference between procedural and object-oriented programs?
What is the purpose of javac exe?
What is balanced tree in java?
Why Do I Get A "permission Denied" Error After Downloading The .jnlp Java Launcher For The Vkvm?
How does linkedhashmap work in java?
How many arguments can be passed to main ()?
Explain the difference between abstract class and interface in java?
Explain the difference between static and dynamic binding in java?
How to sort numbers in java without array?
Can we pass a primitive type by reference in java? How
Is a boolean 1 bit?