Just when I thought I had understood inheritance, I get stuck on a problem...
Let's say I've got an abstract class Animal and several derived classes, like this:
public abstract class Animal
{
public abstract int Age{get;set;}
public abstract bool Hungry{get;set;}
};
public class Dog:Animal
{
public bool PottyTrained{get;set;}
}
public class Cat:Animal
{
public int MiceKilled{get;set;}
}
I now want a method that can handle both Dogs and Cats. I thought I could do it like this:
public List<Animal> FeedAnimals(List<Animal> InAnimals)
{
foreach(var animal in InAnimals)
{
animal.Hungry = false;
}
return InAnimals;
}
but when I try it, the compiler tells me "cannot convert from ..." ...
Am I doing something wrong? Is this because I'm passing lists? Any way around it?