Challenge - 5 Problems
Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
What is the output of this Java code using import?
Consider the following Java code snippet. What will it print when run?
Java
import java.util.ArrayList; public class Test { public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("apple"); list.add("banana"); System.out.println(list.get(1)); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
What error occurs if import is missing?
What error will this Java code produce if the import statement is removed?
Java
import java.util.HashMap; public class Test { public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<>(); map.put("one", 1); System.out.println(map.get("one")); } }
Attempts:
2 left
🔧 debug
advanced2:30remaining
Why does this import cause a conflict?
Given the following code, why does it cause a compilation error?
Java
import java.util.Date; import java.sql.Date; public class Test { public static void main(String[] args) { Date d = new Date(0); System.out.println(d); } }
Attempts:
2 left
📝 syntax
advanced1:30remaining
Which import statement is syntactically correct?
Which of the following import statements is correct in Java?
Attempts:
2 left
🚀 application
expert3:00remaining
How to use fully qualified class name to avoid import conflict?
You have two classes named List in different packages: java.awt.List and java.util.List. You want to use both in the same file without import statements. How do you declare variables of each type?
Attempts:
2 left
