Skip to main content

How to Resolve Error "CS0418: 'class name': an abstract class cannot be sealed or static" in C#

The Compiler Error CS0418 is a logical contradiction error. The message reads: "'ClassName': an abstract class cannot be sealed or static".

In C#, class modifiers define how a class relates to inheritance.

  • abstract: This class is incomplete. It must be inherited to be used.
  • sealed: This class is complete (final). It cannot be inherited.
  • static: This class contains only static members and cannot be instantiated. Implicitly, static classes are also sealed (cannot be inherited).

Combining abstract with either sealed or static creates a paradox: you are telling the compiler that the class must be inherited, but also that it cannot be inherited.

This guide explains these conflicting modifiers and how to choose the right one for your design.

Understanding the Paradox

To visualize why this is an error, think of a door:

  • abstract: "This door must remain open for others to walk through (inherit)."
  • sealed: "This door is locked and welded shut (no inheritance)."

If you declare a class as abstract sealed, you are saying: "This door must be open, but it is welded shut." The compiler rejects this impossibility.

Scenario 1: Abstract and Sealed

This combination is the most direct contradiction. You might encounter this if you want a class to enforce a contract (abstract) but don't want anyone to extend it (sealed), which is conceptually impossible.

Example of error

// ⛔️ Error CS0418: 'BaseEntity': an abstract class cannot be sealed or static.
public abstract sealed class BaseEntity
{
public abstract void Save();
}

Solution: Choose Your Intent

You must decide if this class is a Base (Template) or a Implementation (Final Product).

Option A: It is a Base Class (Remove sealed) Use this if you want other classes to inherit from it.

// ✅ Correct: Allowed to be inherited
public abstract class BaseEntity
{
public abstract void Save();
}

Option B: It is a Final Class (Remove abstract) Use this if the class is finished and should not be extended. You must provide implementations for all methods.

// ✅ Correct: Cannot be inherited, but is fully implemented
public sealed class UserEntity
{
public void Save()
{
Console.WriteLine("Saved");
}
}

Scenario 2: Abstract and Static

A Static Class in C# is a container for global utility methods (like System.Math). Static classes cannot be instantiated (new Math()) and they cannot be inherited (class MyMath : Math).

Because they cannot be inherited, they cannot be abstract.

Example of error

You might try to define a "template" for utility classes.

// ⛔️ Error CS0418: 'UtilityBase': an abstract class cannot be sealed or static.
public static abstract class UtilityBase
{
// You might be trying to force static classes to have a specific method.
// This syntax is invalid for classes.
}

Solution

If you are defining a utility class, just make it static. If you are trying to define a contract (interface) that includes static members, use C# 11 Interfaces.

Option A: Standard Utility Class

// ✅ Correct: Just a static class
public static class StringUtils
{
public static bool IsEmpty(string s) => s.Length == 0;
}

Option B: Static Abstract in Interfaces (C# 11+) If your goal was to force classes to implement a specific static method (e.g., Create()), do not use an abstract class. Use an interface.

// ✅ Correct (C# 11+): Interfaces can define static abstract members
public interface IFactory<T>
{
static abstract T Create();
}

public class UserFactory : IFactory<UserFactory>
{
public static UserFactory Create() => new UserFactory();
}
note

Static Classes are Implicitly Sealed: When you compile a public static class, the compiler actually generates public sealed abstract class in the IL (Intermediate Language) to prevent instantiation and inheritance. However, C# syntax forbids you from typing abstract static manually to avoid confusion with the C# meaning of abstract.

Conclusion

CS0418 enforces logical consistency in your class hierarchy.

  1. Review the Modifiers: You can only pick one major behavior.
  2. Select abstract if you want to create a blueprint for other classes.
  3. Select sealed if you want to prevent inheritance.
  4. Select static if you want a container for global methods (no instances).