December 2001
Intermediate to advanced
416 pages
8h 16m
English
To explicitly prevent derivation from a class, we specify the sealed keyword:
sealed public class BinaryTree { ... }
An attempt to inherit from a sealed class triggers a compile-time error:
// error: BinaryTree is a sealed class
public class RedBlackTree : BinaryTree { ... }
The sealed keyword cannot be applied to either a struct, which is already implicitly sealed, or class declared as abstract, which requires the inherited classes to provide a concrete implementation.
Why do we seal a class?
There is the philosophical aspect, of course. We're making a statement as to our perceived use of the class.
Unfortunately, our perception may be of limited perspicacity. For example, in the next chapter we will need to extend ...
Read now
Unlock full access