Bird
0
0

Given two classes named Logger in packages com.app.utils and com.app.logging, what happens if you import both packages and try to use Logger without qualification?

medium📝 Predict Output Q4 of 15
Java - Packages and Access Control
Given two classes named Logger in packages com.app.utils and com.app.logging, what happens if you import both packages and try to use Logger without qualification?
ACompilation error due to ambiguous reference
BThe Logger from the first imported package is used
CThe Logger from the last imported package is used
DRuntime error occurs
Step-by-Step Solution
Solution:
  1. Step 1: Understand import behavior

    Importing two classes with the same name causes ambiguity.
  2. Step 2: Check compiler response

    Compiler throws an error if class name is ambiguous without qualification.
  3. Final Answer:

    Compilation error due to ambiguous reference -> Option A
  4. Quick Check:

    Ambiguous class names cause compile-time errors [OK]
Quick Trick: Ambiguous imports cause compile errors [OK]
Common Mistakes:
  • Assuming one class overrides the other silently
  • Expecting runtime errors instead of compile errors
  • Believing the first import always wins

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes