ra170
ra170

Reputation: 3683

private constructor, subclassing and sealed

If one can prevent subclassing by declaring private constructor in the base class, why do we need "sealed" keyword? Is it so because CLI can optimize it better? maybe.

Thanks.

Upvotes: 2

Views: 1069

Answers (2)

MaLio
MaLio

Reputation: 2540

If a class is sealed some optimizations can be performed. i.e. the clr could emit .call instruction rather than a .callvirt

Upvotes: 2

Sean
Sean

Reputation: 62532

Because you might want to have public constructors but not allow anyone to derive from your class

Upvotes: 9

Related Questions