sahil kumar

sahil kumar

  • NA
  • 14
  • 7.3k

oops

Sep 19 2013 6:36 AM
can anyone explain me in detail the concept

Animal a2 = new Dog();    means
i want to understand in depth
Animal a2 = new Dog(); a2.Talk(); a2.Sing(); a2.Greet(); //Output Animal constructor Dog constructor Animal talk Dog song Animal says Hello

why above output is coming when we have used new dog()....

public new void Talk() what does this line mean in class dog below

can anyone give me a pdf or note to deeply understand these(oops concept something step by step and with lot of example for beginner
class Animal
{
    public Animal()
    {
        Console.WriteLine("Animal constructor");
    }
    public void Greet()
    {
        Console.WriteLine("Animal says Hello");
    }
    public void Talk()
    {
        Console.WriteLine("Animal talk");
    }
    public virtual void Sing()
    {
        Console.WriteLine("Animal song");
    }
};


class Dog : Animal { public Dog() { Console.WriteLine("Dog constructor"); } public new void Talk() { Console.WriteLine("Dog talk"); } public override void Sing() { Console.WriteLine("Dog song"); } };

and what is abstract and interface are ? why both exist when both does almost same thing


Answers (1)