Sealed Classes Example:
sealedclass Account : Asset
{
long val;
public void Deposit (long x) { ... }
public void Withdraw (long x) { ... }
...
}
Note
•sealedclasses cannot be extended (same as finalclasses in Java),but they can inherit from other classes.
•overridemethods can be declared as sealedindividually.
•Reason:
–Security (avoids inadvertent modification of the class semantics)
–Efficiency (methods can possibly be called using static binding)
No comments:
Post a Comment