Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("For Non Virtual Function");
            Animal animal = new Animal();

            animal.NotVirtualFunction(); //i am an animal
            animal = new Cat();          //dynamic binding?
            animal.NotVirtualFunction(); //i am an animal? but we changed the function using new keyword in Cat class
            animal = new Dog();
            animal.NotVirtualFunction(); //still i am an animal?
            Console.WriteLine("For Virtual Function");
            Animal animal1 = new Animal();

            animal1.AVirtualFunction(); //i am an animal
            animal1 = new Cat();
            animal1.AVirtualFunction(); //i am an cat
            animal1 = new Dog();
            animal1.AVirtualFunction(); //i am an dog

            /*It is optional to reimplement a virtual function it is not necessary to
             * Reimplement it the child class can also use it like a normal function
             * Hum virtual isliye likhte hain function k sath taake agr hum koi new class
             * banayen aur usme humain parent k function ko change krke use krna ho toh humain parent me
             * changes nah krni paren hum parent walay ko override kr len
             * Agr Dog class me AVirtual wala function hata den toh b uske pass wo function mojud hoga
             * aur uski implementation animal class wwali hogi jese normal cases me hota ha*/
        }