Abstract vs Sealed Classes vs Class Members in C#

CsharpServer Side ProgrammingProgramming

The abstract class includes abstract and non-abstract methods. You cannot instantiate an abstract class.

The sealed class prevents inheritance and you cannot use it as a base class.

Abstract Classes

To declare an abstract class, you need to place the keyword abstract before the class definition. An example of class members in an abstract class can be the following that defines an abstract method −

public abstract class Vehicle {
   public abstract void display();
}

The abstract method definition is followed by a semi-colon since it has no implementation.

Sealed Classes

To declare a sealed class, you need to place the keyword sealed before the class definition. The sealed class prevents inheritance and you cannot use it as a base class.

public sealed class Test {
   // Class members comes here
}
raja
Published on 24-Jul-2018 11:46:34
Advertisements