C# Error CS0533 – ‘derived-class member’ hides inherited abstract member ‘base-class member’

C# Compiler Error

CS0533 – ‘derived-class member’ hides inherited abstract member ‘base-class member’

Reason for the Error

You’ll get this error in your C# code when your base class method is hidden.

For example, let’s try to compile the below C# code snippet.

using System;

namespace DeveloperPublishConsoleCore
{
    abstract public class ParentClass
    {
        abstract public void Method1();
    }

    abstract public class ChildClass : ParentClass
    {
        new abstract public void Method1(); 
    }

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

The above program has a ParentClass with an abstract method Method1. The ChildClass inherits from the ParentClass but also has a method Method1 defined with the new keyword. This hides the base class’s method Method1 and C# compiler will throw the error code CS0533.

Error CS0533 ‘ChildClass.Method1()’ hides inherited abstract member ‘ParentClass.Method1()’ DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 12 Active

C# Error CS0533 – 'derived-class member' hides inherited abstract member 'base-class member'

Solution

To fix this error, you’ll need to override the method in the inherited class instead of hiding the base class method.

using System;

namespace DeveloperPublishConsoleCore
{
    abstract public class ParentClass
    {
        abstract public void Method1();
    }

    abstract public class ChildClass : ParentClass
    {
	// This line replaced with override to fix the error code CS0533
        override abstract public void Method1(); 
    }

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

Leave A Reply

Your email address will not be published. Required fields are marked *

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...