-2

Can I set as abstract an abstract function? Can I do this:

public abstract class A
{
   protected abstract void WhateverFunction();
}

public abstract class B:A
{
   protected abstract void WhateverFunction();
}

public abstract class C:B
{
   protected override void WhateverFunction()
   {
      //code here
   }
}

If not, what can I do to simulate this behaviour?

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41
jetFire55
  • 49
  • 5

1 Answers1

3

Yes, but you need to add the override modifier to the function declared on the B class. So, in this case, WhateverFunction is abstract and at the same time overrides the function on A:

public abstract class A
{
    protected abstract void WhateverFunction();
}

public abstract class B : A 
{
    protected abstract override void WhateverFunction(); // HERE
}

public abstract class C : B
{
    protected override void WhateverFunction()
    {
        //code here
    }
}

In this case, you could also simply omit WhateverFunction on class B to achieve the same result.

Marcus Vinicius
  • 1,891
  • 1
  • 19
  • 35