hi Thomas
i knew the answer Alton wrote BUT i tried to confirm it using a program.
guess what? it didnt work for me
so i didnt post my answer,
here is what i wrote and got,
Program:
-------
import java.util.*;
public class ABC {
Calendar c = setCalendar();
public ABC() throws Exception {}
Calendar setCalendar() throws Exception{
Calendar rightNow = Calendar.getInstance();
if (rightNow.get(Calendar.MONTH) == Calendar.AUGUST)
throw new Exception("Don't run this in August");
return rightNow;
}
}
Result of javac:
----------------
ABC.java:5: Exception java.lang.Exception can't be thrown in initializer.
Calendar c = setCalendar();
^
1 error
then i realized why it would not work and wrote the code Prameet came up with later on. that code worked but u specified in the question that only one line needed to change to make the code compile successully and so i thought my answer is invalid
not that i want the book but just to make sure we know the correct answer.
regards
maulin