As a developer if you want to control who can extend your class or interface.
In this enhancement of Java programming language, new keywords are introduced sealed, non-sealed and permit at the class level.
A sealed class or interface can be extended or implemented only by those classes and interfaces permitted to do so. If you try to implement or extend to other class which is not permitted then the code will not compile. For example,
public sealed class Point permits Line
A permit keyword defines which are the subclasses or interfaces can be extended or implemented from this class. For example,
public sealed class Point permits Line
Point class only permits Line class to extend directly.
A non-sealed class or interface will allow this class to be extended.
For example,
public non-sealed class Line
Permitted class Line is open for any unknown class extension.
Very crisp and to the point.
ReplyDeleteIs 'non-sealed' a default behaviour?
No. You have to be specific.
Delete