Hi all ranchers,
The code below is saved using the file named "ATest.java".
public 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[]) {
AnInterfaceImpl ai = new AnInterfaceImpl();
ai.methodOne();
}
}
If I try to compile this code, I got this error:
"class AnInterface is public, should be declared in file named AnInterface.java"
Why does JVM complains about the public access modifier? And besides, AnInterface was declared as an interface and not a class. The code also contains ATest.java declared as public. So why is this complaining?