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 / nil
We can have a simple program, I have issues with staring 2
threads at the same time, you guys can have a look and let
me know how could i start two threads at the same time.
the code is as follows, we would have a separate class for
each thread, and then we would have a tester class
package threads;
public class Thread1 implements Runnable{
public void run() {
System.out.println("Hello how are you");
}
}
package threads;
public class Thread2 implements Runnable{
public void run() {
System.out.println("Hello");
}
}
then this would be the tester class
package threads;
public class Thread_test {
public static void main(String[] args) {
Thread thread1 = new Thread(new Thread1());
Thread thread2 = new Thread(new Thread2());
thread1.start(); /* starting the two threads at the same
time, Any suggestions */
thread2.start();
}
}
| Is This Answer Correct ? | 0 Yes | 8 No |
Post New Answer View All Answers
Difference between linkedlist and arraylist.
What’s meant by anonymous class?
What is string data type?
Can we override a variable in java?
Why java is called not pure object oriented language?
How do you stop a thread in java?
Is java same as core java?
What is initial size of arraylist in java?
Does every java program need a main?
Is it necessary that each try block must be followed by a catch block?
What is a pointer and does java support pointers?
Why call by value prevents parameter value change?
What is the basic concepts of OOPS?
Can a hashset contain duplicates java?
Why java does not support pointers?