Java mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each. Score 60% or more to pass; your best score is kept.
Java programs need the full compiler, coming soon to CodeMIRAI, so these mocks are questions only for now; every lesson's coding practice still has its problems and worked solutions.
- 01Mock test 112 questions · 45 minutes · 12 points
- 02Mock test 212 questions · 45 minutes · 12 points
- 03Mock test 312 questions · 45 minutes · 12 points
Part A · 12 questions
- With show(int) and show(double) defined, which runs for show(7)?
- How many times does for (int i = 0; i < 5; i++) run its body?
- On a List<Integer> holding [5, 7, 9], what does list.remove(1) do?
- int x = 5; System.out.println(x++); What is printed?
- How do you compare two Strings' text in Java?
- Which type should store true or false?
- When does a finally block run?
- What does "Java Programming".substring(0, 4) return?
- How many interfaces can a class implement?
- Which form avoids fall-through entirely?
- What is the benefit of writing @Override?
- What does this print? int s = 0; for (int i = 1; i <= 4; i++) { s += i; } System.out.println(s);
Part A · 12 questions
- What does super(name) do in a subclass constructor?
- Which pair of methods is a valid overload?
- You put("apples", 40) and then put("apples", 35). What does get("apples") return?
- What happens when you cast an object to a class it doesn't belong to?
- Why does String start with a capital letter?
- In a constructor, what does this.name = name; do?
- How should you check whether two Strings contain the same text?
- In a right-angled star triangle, the inner loop runs:
- What does the Java compiler produce?
- What does map.get(key) return when the key isn't in a HashMap?
- Two variables refer to the same object, and one changes a field. What does the other see?
- What is the GCD of 48 and 36?
Part A · 12 questions
- How can a program avoid crashing when the user types a word instead of a number?
- After nextInt() reads a number at the end of a line, what does the next nextLine() return?
- What happens when a recursive method has no base case?
- In nums.stream().filter(n -> n > 5).map(n -> n * 2), when does the filtering actually happen?
- What does void mean in static void greet(String name)?
- What return type does a constructor have?
- What does (int) 5.9 evaluate to?
- Why make fields private?
- Why is polymorphism better than a chain of if-else checks on an object's type?
- A method sets its int parameter to 100. What happens to the caller's variable?
- What is wrong with if (total > 100); { applyDiscount(); }
- An array has 5 elements. What is the index of the last one?