Skills101
← All practice quizzes

Quiz: Immutability and Value Objects

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

How to write a class whose objects can never change, why that removes whole categories of bugs, and how value objects like Money and Marks compare by value with equals, hashCode and Java records.

Log in to take the quiz

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

  1. Question 1

    What does this print?

    public class Main {
        public static void main(String[] args) {
            String s = "java";
            s.toUpperCase();
            s.concat("!");
            System.out.println(s);
        }
    }
    
  2. Question 2

    A class has only private final List<String> items; and no setters. Why can it still be mutable?

  3. Question 3

    Which line correctly makes a defensive, unmodifiable copy of a list parameter?

  4. Question 4

    Why is it important to override hashCode whenever you override equals?

  5. Question 5

    What does this print?

    record Point(int x, int y) {}
    
    public class Main {
        public static void main(String[] args) {
            Point a = new Point(1, 2);
            Point b = new Point(1, 2);
            System.out.println((a == b) + " " + a.equals(b));
        }
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →