Reputation: 157
I have created a class and a subclass. I also have an interface in the parent class. How can I make the child class implement the interface?
The code is:
class Car
{
public interface ISmth
{
void MyMethod();
}
}
class MyCar : Car
{
//implement the interface
}
Upvotes: 2
Views: 4064
Reputation: 117064
This is how your code should probably be laid out.
public interface ISmth
{
void MyMethod();
}
class Car
{
}
class MyCar : Car, ISmth
{
public void MyMethod()
{
}
}
There doesn't seem to be a reason to nest ISmth
in Car
, but if you do have one you certainly could do it.
Upvotes: 4
Reputation: 133
You need to declare MyCar like that:
class MyCar: Car, Car.ISmth {}
Upvotes: 3