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?
You can prevent a class from being subclassed by using the final keyword in the class's declaration. Similarly, you can prevent a method from being overridden by subclasses by declaring it as a final method. An abstract class can only be subclassed; it cannot be instantiated.
We can access protected members of a class in its subclass if both are present in the same package.
The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class. However, inheritance is transitive.
With protected , all public members of the base class are inherited as protected in the derived class. Conversely, if the most restricting access level is specified ( private ), all the base class members are inherited as private .
The keyword you are searching is "sealed".
MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With