I'm trying to understand the Polymorphism, but I cannot understand it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
internal class Program
{
static void Main(string[] args)
{
Parent Andrew = new Child();
}
class Parent
{
public int age;
public string name;
public virtual void message()
{
Console.WriteLine("I'm a parent");
}
}
class Child : Parent
{
public string childName;
public override void message()
{
Console.WriteLine("I'm a child");
}
}
}
}
What's the point of creating an instance of "Parent" class and allocating it the pattern of inherited class "Child". I saw this on some tutorials, and I cannot understand why would we do that if we cannot access "Child" class variables through this instance created. Thank you =). Hope I pointed well my problem, if not, let me know.