namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
          
            Person p1 = new Student();
            
            p1.Sing();
            p1.Run();
            Console.WriteLine(p1.GetType().Name);
            Console.Read();
        }
    }
    class Person
    {
       
        public  void Run() {
            Console.WriteLine("Person Run");
        }
        public virtual void Sing() {

            Console.WriteLine("Person Sing");
        }
    }
    class Student : Person
    {

        public  void Run()
        {
            Console.WriteLine("Student Run");
        }
        public override void Sing()
        {
            Console.WriteLine("Student Sing");
        }
       
    }
    
}

Object type is Student but why it doesn't run the Student Run method ,if student run method overides we can get the Result of "Student Run"...What is the concept of this

Edited 5 Years Ago by MrBlack: n/a

Because when you do new Student(), all it is saying is run a new instance of class Student(run the constructor of the class).

When you assign a new instance of Student to a variable of type Person, when you run sing and run methods of the object p1, the methods of class Person are called.

Help at all?

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
          
            Person p1 = new Student();
            
            p1.Sing();
            p1.Run();
            Console.WriteLine(p1.GetType().Name);
            Console.Read();
        }
    }
    class Person
    {
       
        public  void Run() {
            Console.WriteLine("Person Run");
        }
        public virtual void Sing() {

            Console.WriteLine("Person Sing");
        }
    }
    class Student : Person
    {

        public  void Run()
        {
            Console.WriteLine("Student Run");
        }
        public override void Sing()
        {
            Console.WriteLine("Student Sing");
        }
       
    }
    
}

Object type is Student but why it doesn't run the Student Run method ,if student run method overides we can get the Result of "Student Run"...What is the concept of this

You need to tell the compiler in some way that the virtual method has actually been supplied by the inherited class, otherwise it doesn't know about it.
In order to tell the compiler this you use the keyword "override".
If you don't specify this, the compiler will think that even though there is a function with the same name, it is local to the the inherited class, and as such not visible in the inheriance hierachy.

Edited 5 Years Ago by Bridgekeepers: corecting some missspelling