new to C#.
I have a strange problem, as I am learning C# now, the following code is supposed to output the same value:
public class Animal {
public void sound() {
Console.WriteLine("...");
}
}
public class Dog : Animal {
public void sound() {
Console.WriteLine("Woof");
}
}
public class Cat : Animal {
public void sound() {
Console.WriteLine("Meaw");
}
}
// in Main(){};
Animal animal = new Animal();
Dog dog = new Dog();
Cat cat = new Cat();
animal.sound();
dog.sound();
cat.sound();
From what I have learned the value for all three methods should be the same, as in: ...
but I get the following:
...
Woof
Meaw
How can this be possible without using the virtual
and override
properties?