Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance/classes in C#

I am new to C#, and are trying to understand classes and "is a" relationships. I've been trying to get a piece of code to work, but I can't seem to get it right.

It looks like this: http://pastebin.com/cQDusptB

I have a base class, Mammal, which one should be able to create instances of, giving the name of the mammal as input. I also have a class, Dog, which is a Mammal. One should be able to create an instance of this too, in the same manner as Mammal.

Can anyone see my flaw(s)? If yes, can you please explain what i misunderstood/forgot?

like image 677
Treeline Avatar asked Jan 21 '26 13:01

Treeline


1 Answers

When posting questions like this it is helpful to also post the error message the compiler gave you.

Can anyone see my flaw(s)?

You have a virtual constructor.

can you please explain what i misunderstood/forgot?

Constructors are not inherited in C# and therefore it makes no sense to mark them as either virtual or override.

like image 52
Eric Lippert Avatar answered Jan 23 '26 01:01

Eric Lippert