Skills101
← All practice quizzes

Quiz: Records and Sealed Classes

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

Replace 40 lines of constructor, getters, equals, hashCode and toString with one record line, validate data in a compact constructor, and use sealed classes to fix exactly which subclasses may exist.

Log in to take the quiz

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

  1. Question 1

    What does this print?

    record Point(int x, int y) { }
    public class Main {
        public static void main(String[] args) {
            Point p = new Point(3, 4);
            System.out.println(p);
        }
    }
    
  2. Question 2

    What is the accessor method for the component marks in record Student(String name, int marks)?

  3. Question 3

    What does this print?

    import java.util.*;
    record City(String name) { }
    public class Main {
        public static void main(String[] args) {
            Set<City> set = new HashSet<>();
            set.add(new City("Pune"));
            set.add(new City("Pune"));
            System.out.println(set.size());
        }
    }
    
  4. Question 4

    Which is true about records?

  5. Question 5

    What is a compact constructor in a record used for?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →