Abstract vs Sealed Classes vs Class Members in C#


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
}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

962 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements