The following code is for Questions 81 and 82
//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");
}
}
Question 81.
Read the code below carefully.
public class ATest
{
public static void main(
String args[])
{
AnInterface ai = new AnInterfaceImpl();
ai.methodOne();
}
}
Attempting to compile and run the above code
1) Will cause a compile time error. (Line 5 : Exception must be caught or thrown by main(String))
2) Will cause a compile time error for Class AnInterfaceImpl. The method methodOne() be declared with "throws Exception".
3) Will cause no compile time error and print "I will never throw and Exception the screen".
Will Cause a run time error .
-----------------------------------------------------------------
Question 82.
Read the code below carefully.
public class ATest
{
public static void main(String args[])
{
AnInterfaceImpl ai = new AnInterfaceImpl();
ai.methodOne();
}
}
Attempting to compile and run the above code
1) Will cause a compile time error. (Line 5 : Exception must be caught or thrown by main(String))
2) Will cause a compile time error for Class AnInterfaceImpl. The method methodOne() be declared with "throws Exception".
3) Will cause no compile time error and print "I will never throw and Exception the screen".
Will Cause a run time error .
Ans 81)1
82)3
Can someone please explain me the output.
Thanks in advance.