🎴 Flashcard Mode

Java and Perl Programming Quiz

Card1 / 20
Mastered0
Review0
QuestionClick to flip

12 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 //Base.java package Base; class Base{ protected void amethod(){ System.out.println("amethod"); }//End of amethod }//End of class base package Class1; //Class1.java public class Class1 extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); }//End of main }//End of Class1

AnswerClick to flip back
A
d. Compile error: Superclass Class1.Base of class Class1.Class1 not found
💡 Explanation:

Class1 is in package Class1, Base is in package Base. Class1 extends Base. When Class1 tries to create 'new Base()', the compiler looks for Base.Class1.Base (inner class interpretation) because of how package names interact. The actual Base class is in a different package and isn't found with that qualification. This causes 'Superclass Class1.Base of class Class1.Class1 not found' - the compiler is confused about the class hierarchy due to package naming.

Change Mode