Bird
0
0

You want to use both java.util.Date and java.sql.Date in the same Java file. How should you import them to avoid confusion?

hard📝 Application Q15 of 15
Java - Packages and Access Control
You want to use both java.util.Date and java.sql.Date in the same Java file. How should you import them to avoid confusion?
Aimport java.util.Date; // Use fully qualified name for java.sql.Date in code
Bimport java.util.*; import java.sql.*;
Cimport java.util.Date; import java.sql.Date;
Dimport java.util.*; import java.sql.Date;
Step-by-Step Solution
Solution:
  1. Step 1: Understand class name conflict

    Both packages have a class named Date, so importing both directly causes ambiguity.
  2. Step 2: Use import for one and full name for the other

    Import one Date class and use the full package name for the other to avoid confusion.
  3. Final Answer:

    import java.util.Date; // Use fully qualified name for java.sql.Date in code -> Option A
  4. Quick Check:

    Import one Date, fully qualify the other [OK]
Quick Trick: Import one class, fully qualify the other to avoid name clash [OK]
Common Mistakes:
  • Importing both classes directly causing ambiguity
  • Using wildcard imports causing confusion
  • Not using fully qualified names when needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes