Kaushiki Singh said:
(Mon, Mar 7, 2011 02:11:31 AM)
I m also in doubt with this answer I think B option should be the right answer. Can you please give the explaination for this answer.
Sundar said:
(Mon, Mar 7, 2011 02:58:51 AM)
@All
The given answer is correct. Don't get confused.
A. Thread t = new Thread(X);
Wrong. Because, here X is the ClassName not an object.
B. Thread t = new Thread(X); t.start();
Wrong. Because, here X is the ClassName not an object. So thread cannot be started. It would have been correct if it was written like: Thread t = new Thread(new X()); t.start();
D. Thread t = new Thread(); x.run();
Wrong. Here, object 'x' doesn't make any sense.
But, Option C: is correct
X run = new X(); //Creates objects that implements run() as per Runnable interface
Thread t = new Thread(run); // Creates thread
t.start(); // Starts the thread.
Note: The above three statements can be written as simply
(new Thread(new X()).start();
Hope this help you. Have a nice day!
Pradeep said:
(Sun, Apr 24, 2011 06:40:45 AM)
The process of working with a thread
1. create an object as here
x run= new x();
2. create a thread and attach an object as here
thread t = new thread(run);
3. start the thread
t.start();
Gopichand said:
(Thu, May 12, 2011 01:00:32 PM)
I got confused, how it's work please explain it detail.
Manivannan.K said:
(Tue, Sep 6, 2011 10:49:35 PM)
Ya its correct. Whatever class used in java we must used called the object to a responsible for the class so after thread class created then thread will be run in java programs.
Sri Rajyalakshmi said:
(Sun, Sep 11, 2011 12:16:13 PM)
Actually I am also confused thanks for clearing this.
Vk007 said:
(Thu, Mar 1, 2012 11:28:50 PM)
Hi guys,
The given answer is correct and there is nothing confusing cause:.
1. Thread need to know where it has to run so by passing object of that class we convey this.
2. To call run method, we call start method of thread class.