Java Quiz

Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.

1. What does the javac tool do?

2. Which file name must contain public class Invoice?

3. What does System.out.println("3 + 4 = " + 3 + 4) print?

4. What is the value of 7 / 2 in Java?

5. What is (int) 9.99?

6. What does Integer.MAX_VALUE + 1 give?

7. How should you compare the contents of two strings?

8. What happens to s after s.toUpperCase(); (result not stored)?

9. Which loop always runs its body at least once?

10. What is the last valid index of an array with length 5?

11. Why doesn't the arrow form of switch need break?

12. A method receives an int and changes it. What happens to the caller's variable?

13. What does a recursive method need to stop?

14. What does static mean on a field?

15. What happens to the free default constructor when you write your own constructor?

16. Which access modifier hides a member from every other class?

17. How many classes can a Java class extend?

18. Animal a = new Cat(); — which speak() runs for a.speak()?

19. Can you create an object of an abstract class with new?

20. What does a record automatically generate?

21. If you override equals, what else must you override?

22. What's the difference between checked and unchecked exceptions?

23. What does try-with-resources guarantee?

24. Why does Integer c = 1000, d = 1000; c == d give false?

25. Which collection keeps elements unique and sorted?

26. What does map.merge(word, 1, Integer::sum) do?

27. Which is a valid lambda for Predicate<String>?

28. When does a stream pipeline actually process elements?

29. What do sealed interfaces add to pattern-matching switches?

30. Why does count++ from several threads lose updates?

Want more practice? Try the exercises, or revisit any lesson from the course home.