J. Does J. Does - 7 months ago 23
Java Question

C# extends implements and abstract classes

A few days ago, I started "recoding" project from Java into C#. I encountered a few errors. The "biggest" one that I get the following error:


does not implement interface member


C# Code:



class Player : Entity
{
//Main Class
public void Kill(){ ... }
}

abstract class Entity : MapObject, Killable
{
//...
}

abstract class MapObject
{
//...
}

interface Killable
{
void Kill();
}


In my Java project, the interface class is abstract, Entity class looks like:

abstract class Entity extends MapObject implements Killable {...}


And it works... So what is wrong with my C# code ?

Answer

You should define method Kill() in Entity class. If you don't need implementation of this method in abstract class, the method Kill() in Entity should be abstract:

abstract class Entity : MapObject, Killable
{
    public abstract void Kill(); // or without "abstract" if method needs a body
}