HomeCSharpC# Error CS0418 – ‘class name’: an abstract class cannot be sealed or static

C# Error CS0418 – ‘class name’: an abstract class cannot be sealed or static

C# Compiler Error

CS0418 – ‘class name’: an abstract class cannot be sealed or static

Reason for the Error

You’ll get this error in your C# code when you are trying to mark an abstract class as sealed.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    public abstract sealed class Employee  
    {
    }

    class Program
    {      
        static void Main(string[] args)
        {           
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0418 when you compile the above C# program because you are using the using the sealed keyword on the abstract class. In C#, an abstract class cannot be used for instantiating unless you inherit or derive the abstract class. There won’t be any meaning if you are making the abstract class as sealed. The same applies for the abstract class marked as static as well.

Error CS0418 ‘Employee’: an abstract type cannot be sealed or static DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 5 Active

C# Error CS0418 – 'class name': an abstract class cannot be sealed or static

Solution

You can avoid this error in your C# code by ensuring that you don’t mark the abstract class as either sealed or static.

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...