Inheritance enables you to create a new class that reuses, extends, and modifies the behavior that is defined in another class. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. However, all classes in C# implicitly inherit from the Object class that supports .NET class hierarchy and provides low-level services to all classes.

C# doesn’t support multiple inheritance. That is, you can specify only one base class for a derived class.

To inherit from a base class:

class DerivedClass:BaseClass {}

By default all classes can be inherited. However, you can specify whether a class must not be used as a base class, or create a class that can be used as a base class only.

To specify that a class cannot be used as a base class:

public sealed class A { }

To specify that a class can be used as a base class only and cannot be instantiated:

public abstract class B { }

Sources:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/object-oriented-programming#Properties

Last modified: March 20, 2019

Author

Comments

Write a Reply or Comment