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 a newline character in java?
How will you communicate between two applets?
What is identifier in java?
What is the use of math abs in java?
What is a method declaration?
What are void pointers?
Why do we need singleton class?
What is java util?
What is java developer skills?
Can we override the overloaded method?
what is use of functional interface in java 8?
What is super in java?
Differentiate between == and equals().
How to create an interface?
What is java basic concept?