//-------------------------the code---------------------//
interface AnInterface
{
public void methodOne() throws Exception;
}
class AnInterfaceImpl implements AnInterface
{
public void methodOne()
{
System.out.println("I will never throw an exception");
}
}
public class ATest
{
public static void main(
String args[])
{
AnInterface ai = new AnInterfaceImpl();
ai.methodOne();
}
}
Attempting to compile and run the above code
A) Will cause a compile time error. (Line 5 : Exception must be caught or thrown by main(String))
B) Will cause a compile time error for Class AnInterfaceImpl. The method methodOne() be declared with "throws Exception".
C) Will cause no compile time error and print "I will never throw and Exception the screen".
D) Will Cause a run time error .
the given ans is :A;
when I change the main method declarationof class Atest to : public static void main(String args[]) throws Exception
everything is ok!
But I think in the main method ,the instance ai only invoke the method methodOne which override superclass's methodOne,and in it��s declareation ,it doesn��t throws any Exception ,as a result ,the main needn��t throws the Exception.
but ......the facts wins me!
could you give me the reason!