Basic Java

Test Your Knowledge

Answer all 10 questions, then submit to see your score.

1. What will this code print?

Class<?> a = "hello".getClass();
Class<?> b = String.class;
System.out.println(a == b);

2. What will this code print?

record Measurement(double reading) {}
Measurement m1 = new Measurement(Double.NaN);
Measurement m2 = new Measurement(Double.NaN);
System.out.println(m1.equals(m2));

3. Which of the following is true about an enum's relationship with other types?

4. What happens when you try to unbox a null wrapper in Java?

5. Which of the following methods can be used to inspect a String in Java?

6. Inside a compact constructor, which of the following is true?

7. By default, what happens if you call Files.writeString(path, content) on a file that already exists?

8. In a switch expression, when is the `yield` keyword needed?

9. What exception might be thrown when using Scanner to read from a file?

10. What is the consequence of using Files.lines(path) without try-with-resources?