How have recent updates in Java (like records, sealed classes) impacted object-oriented programming principles?

Recent Java features such as Records and Sealed Classes have strengthened object-oriented design by reducing boilerplate code, improving immutability, and providing better control over inheritance. These enhancements allow developers to build cleaner, safer, and more maintainable applications while still adhering to core OOP principles like encapsulation, abstraction, and polymorphism.

Key Points

Example

In a payment system, a Payment class can be declared as sealed and allow only CreditCardPayment, UpiPayment, and NetBankingPayment subclasses. Similarly, a Customer record can represent immutable customer information without writing boilerplate code.

public record Customer(
        Long id,
        String name) {
}

public sealed class Payment
        permits CreditCardPayment,
                UpiPayment {
}

final class CreditCardPayment
        extends Payment {
}

final class UpiPayment
        extends Payment {
}

Interview Tip

A concise interview answer is: Records and Sealed Classes modernize Java OOP by promoting immutability, reducing boilerplate code, and providing controlled inheritance. Records simplify data-carrying objects, while Sealed Classes improve type safety by restricting which classes can extend a hierarchy, resulting in cleaner and more maintainable designs.

Last updated: 1 November 2026

Previous question: Can you change a final field using reflection?

Next question: How would you design a system that supports different payment methods (credit card, PayPal, cryptocurrencies) using interfaces and abstract classes?

More Core Java - Level V (Expert) interview questions

All Core Java - Level V (Expert) questions