clarification on this Exceptioncode required//Contents of File AnInterface.java
public interface AnInterface
{
public void methodOne() throws Exception;
}
//Contents of File AnInterfaceImpl.java
public class AnInterfaceImpl implements AnInterface
{
public void methodOne()
{
System.out.println("I will never throw an exception");
}
}
Read the code below carefully.
public class ATest
{
public static void main(
String args[])
{
AnInterface ai = new AnInterfaceImpl();
ai.methodOne();
}
}
when i execute this code i got a compiletime error saying unhandled exception by main ,why so ,actually ai.methodOne() is going to call the method in AnInterfaceImpl which is not throwing any Exception if i remove throws Exception i got the output as
"I will never throw an exception" what i was Expecting.