What is the point of extending a sealed class with a non-sealed class?

Because in real-world APIs, sometimes we want to support specific extension points while restricting others. The Shape examples are not particularly evocative, though, which is why it might seem an odd thing to allow. Sealed classes are about having finer control over who can extend a given extensible type. There are several reasons you might … Read more

What are sealed classes in Java 17?

You can follow this link for examples. In short sealed classes gives you the control of which models, classes etc. that can implement or extend that class/interface. Example from the link: public sealed interface Service permits Car, Truck { int getMaxServiceIntervalInMonths(); default int getMaxDistanceBetweenServicesInKilometers() { return 100000; } } This interface only permits Car and … Read more