Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
42
"I'm not back." - Bill Harding, Twister
42
Originally posted by M Rama:
Which means that the thread object first looks at its own run method and if doesn't find out, will look at the runnable object's.
public class StartInThreadAndRunable extends Thread implements Runnable {
StartInThreadAndRunable(){
}
StartInThreadAndRunable(Runnable r) {
super(r);
}
public void run() {
System.out.println("Thread or Runnable?" + this);
}
public static void main(String[] args) {
Runnable r = new StartInThreadAndRunable();
Thread t2 = new StartInThreadAndRunable(r);
t2.start();
}
}
Output: Thread or Runnable? Thread[Thread-1,5,main]
SCJP (In Progress)
Thread-1, 5 and main represent the thread's name, priority and thread group respectively.
SCJP (In Progress)
SCJP (In Progress)