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


Please Help Members By Posting Answers For Below Questions

What is a newline character in java?

781


How will you communicate between two applets?

858


What is identifier in java?

777


What is the use of math abs in java?

740


What is a method declaration?

727


What are void pointers?

978


Why do we need singleton class?

734


What is java util?

788


What is java developer skills?

736


Can we override the overloaded method?

802


what is use of functional interface in java 8?

783


What is super in java?

769


Differentiate between == and equals().

790


How to create an interface?

825


What is java basic concept?

776