can you give me a simple example of inheritance and polymorphism, so it could be fully clear and understandable?
using C# would make it more clear, as I already lear
Let's use my favorite verb and we find:
http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29
http://msdn.microsoft.com/en-us/library/ms173152%28v=vs.80%29.aspx
Polymorphism and Inheritance are pivotal, need-to-be-ingrained and fundamental concepts to C# and object oriented programming. saying you know C# and not this is like knowing how to speak English and have no concept of what the alphabet is. Sorry to be blunt, but it is true.
From the Wiki link above (this is not mine), here is an example of Polymorphism (converted to C#...)
public class Animal
{
public virtual String talk() { return "Hi"; }
public string sing() { return "lalala"; }
}
public class Cat : Animal
{
public override String talk() { return "Meow!"; }
}
public class Dog : Animal
{
public override String talk() { return "Woof!"; }
public new string sing() { return "woofa woofa woooof"; }
}
public class CSharpExampleTestBecauseYouAskedForIt
{
public CSharpExampleTestBecauseYouAskedForIt()
{
write(new Cat());
write(new Dog());
}
public void write(Animal a) {
System.Diagnostics.Debug.WriteLine(a.talk());
}
}