Mister Dev
Mister Dev

Reputation: 10441

How to make a class protected for inheritance?

I would like to do the same thing I do in Java with the final keyword. I tried to use the const keyword, but it doesn't work. How can I prevent other classes from inheriting from my class?

Upvotes: 6

Views: 350

Answers (3)

Dzmitry Huba
Dzmitry Huba

Reputation: 4521

In general you should mark your type with sealed keyword in case you want prevent derivation. However is some cases it is not appropriate. For example, you want to allow types from your assembly to derive from your publicly accessible type but prevent third parties from derivation.

Here few tricks which allow you to do this:

Upvotes: 2

MOZILLA
MOZILLA

Reputation: 5970

"NonInheritable" for VB.NET

MSDN

Upvotes: 5

Patrick Desjardins
Patrick Desjardins

Reputation: 140803

The keyword you are searching is "sealed".

MSDN

Upvotes: 18

Related Questions