Problem with abstract method.

DC A adc4444@hotmail.com
Fri Nov 7 06:31:00 GMT 2003


Hi! I've a question. Suppose there's a java program like below:
import java.util.Timer;
import java.util.TimerTask;
/**
* Simple demo that uses java.util.Timer to schedule a task to execute
* once 5 seconds have passed.
*/
public class Reminder {
 Timer timer;
 public Reminder(int seconds) {
 timer = new Timer();
 timer.schedule(new RemindTask(), seconds*1000);
 }
 class RemindTask extends TimerTask {
 public void run() {
 System.out.println("Time's up!");
 timer.cancel(); //Terminate the timer thread
 }
 }
 public static void main(String args[]) {
 System.out.println("About to schedule task.");
 new Reminder(5);
 System.out.println("Task scheduled.");
 }
}
The output is:
Task scheduled.
five second later output:
Time's up!
Here when default constructor new RemindTask() is passed on as an argument 
of timer object's schedule method, why the abstract method run() is executed 
five second later 'cause the run() method wasn't called from anywhere in the 
program? Does anyone know?
Thanks.
--MD
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /