Bird
0
0

Consider this code: package com.example; public class Demo {} // In another file: import com.example.*; import com.example.Demo; What is the problem here?

medium📝 Debug Q7 of 15
Java - Packages and Access Control
Consider this code: package com.example; public class Demo {} // In another file: import com.example.*; import com.example.Demo; What is the problem here?
ANo problem, code is correct
BMissing package declaration
CClass Demo is not public
DDuplicate import of the same class
Step-by-Step Solution
Solution:
  1. Step 1: Analyze imports

    Importing 'com.example.*' already includes Demo class, so importing Demo explicitly is redundant.
  2. Step 2: Understand Java import rules

    Java compiler ignores redundant imports and allows them; no compilation error occurs.
  3. Final Answer:

    No problem, code is correct -> Option A
  4. Quick Check:

    Redundant imports are allowed in Java [OK]
Quick Trick: Redundant imports via wildcard and explicit are fine [OK]
Common Mistakes:
  • Thinking duplicate imports cause compile errors
  • Confusing with ambiguous name imports
  • Assuming class visibility issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes