Skills101
← Java — Intermediate

Java Intermediate — Test 1

15 questions19 minPass: 60%+30 XP on first passFree sample test

15 questions · 19 minutes · intermediate level, with an explanation for every answer.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is the output?

    class Main {
        static void change(int x, int[] arr) { x = 99; arr[0] = 99; }
        public static void main(String[] args) {
            int x = 1; int[] arr = {1};
            change(x, arr);
            System.out.println(x + " " + arr[0]);
        }
    }
    
  2. Question 2

    What does static on a method mean?

  3. Question 3

    What is the output?

    StringBuilder sb = new StringBuilder("abc");
    sb.append("de").reverse().insert(0, "*");
    System.out.println(sb + " " + sb.length());
    
  4. Question 4

    What is the output?

    Set<String> s = new TreeSet<>(List.of("pear", "apple", "fig", "apple"));
    System.out.println(s);
    
  5. Question 5

    What is the output?

    Map<String, Integer> m = new HashMap<>();
    for (String w : "a b a c b a".split(" ")) m.put(w, m.getOrDefault(w, 0) + 1);
    System.out.println(m.get("a") + " " + m.get("b") + " " + m.get("z"));
    
  6. Question 6

    Which is a checked exception that the compiler forces you to handle or declare?

  7. Question 7

    What is the main difference between an abstract class and an interface (Java 8+)?

  8. Question 8

    If two objects are equal by equals(), what must be true?

  9. Question 9

    What is the output?

    List<Integer> list = new ArrayList<>(List.of(10, 20, 30, 40));
    list.remove(1);
    list.remove(Integer.valueOf(40));
    System.out.println(list);
    
  10. Question 10

    What is the output?

    class Main {
        static int add(int a, int b) { return a + b; }
        static double add(double a, double b) { return a + b + 0.5; }
        public static void main(String[] args) {
            System.out.println(add(2, 3) + " " + add(2.0, 3));
        }
    }
    
  11. Question 11

    What is the output?

    int[][] g = {{1, 2, 3}, {4, 5, 6}};
    int t = 0;
    for (int i = 0; i < g.length; i++) t += g[i][g[i].length - 1 - i];
    System.out.println(t + " " + g[1].length);
    
  12. Question 12

    Which collection gives O(1) average get/put by key?

  13. Question 13

    What is the output?

    class Animal { String sound() { return "..."; } }
    class Dog extends Animal { String sound() { return "Woof"; } }
    public class Main {
        public static void main(String[] args) {
            Animal a = new Dog();
            System.out.println(a.sound());
        }
    }
    
  14. Question 14

    What is the output?

    String a = "hi";
    String b = "hi";
    String c = new String("hi");
    System.out.println((a == b) + " " + (a == c) + " " + a.equals(c));
    
  15. Question 15

    What is the output?

    class Main {
        static int f() {
            try { return 1; }
            finally { System.out.print("F "); }
        }
        public static void main(String[] args) { System.out.println(f()); }
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →