import java.util.Timer;
import java.util.TimerTask;
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"); // l4
timer.cancel();
}
}
public static void main(
String args[]) {
System.out.println("About to schedule task "); // l1
new Reminder(58); l2
System.out.println("Task scheduled"); l3
}
}
Any one explain me the execution flow of above example.
According to me l1,l2,l3,l4 should get executed. After priting l1 it should wait for some time to print l2 instead of its print l1,l3 waiting for some time then printing l4. AFter printing l1 control should go to Constructor and wait for some time(seconds). Why is not doing?
Thanks.