Explain the difference between a final class and an abstract class, and when would you want to prevent a class from being inherited?
Last updated
An
abstractclass is an incomplete base that cannot be instantiated and must be extended. Afinalclass is complete, and extending it is a fatal error.Individual methods can also be marked
finalto block overriding while still allowing subclassing.Prevent inheritance for value objects and immutable types, and for security- or correctness-critical logic. It also signals composition over extension.