You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java
1) Compile Error: Methods in Base not found 2) Compile Error: Unable to access protected method in base class 3) Compilation followed by the output "amethod" 4)Compile error: Superclass Class1.Base of class Class1.Class1 not found
Did you correctly paste the code? The question states that both classes are in the same directory, so it makes no sense that they are in different packages. If you remove the package declarations from the code then you'll see that answer 4 is indeed correct.
Joined: Feb 28, 2007
Yup Custer, I have correctly pasted the code, the answer to this question says "This question tried to make you fool against the automake feature of the javac if classfile(that your class is referencing to) doesn't exist it will automatically create that too".
But this is not the issue!
Did you get the question? Please tell me the correct answer!
I am not sure if the import statement fixes the glitch.
Base (Class) itself has default access. So the class is not visible outside the package.
Let the two files be in the same directory or different directory, when you try to compile Class1 a) It should be under a directory Class1. (Class1/Class1.java) b) Since there was no import statement for Base, the compiler assumes that Base is in the same directory, so searches for Class1.Base and doesn't find it.