Grokking Java Interview Questions
Vote

0% completed

​

Sealed Classes and Immutable Class Design

A class or interface can name the types that may directly extend or implement it, and Java then rejects every other direct subtype. Such a type is called sealed. A class can also be written so that none of its objects changes in any visible way after construction. Such a class is called immutable.

Both designs remove possibilities. A sealed type limits who may add a subclass, and an immutable class limits what may happen to an object. The first two questions cover the rules of sealed and the reason to use it

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content